mheyman / Isopoh.Cryptography.Argon2

Fully managed .Net Core implementation of Argon2
Other
183 stars 7 forks source link

OutOfMemoryException when creating Argon2() #39

Open tg24 opened 3 years ago

tg24 commented 3 years ago

From time to time I've got an OutOfMemoryException when doing the following in version 1.1.10 (November, 18th 2020):

var argon2A = new Argon2(config);

My configuration looks like this:

{Isopoh.Cryptography.Argon2.Argon2Config}
    AssociatedData: null
    ClearPassword: false
    ClearSecret: false
    HashLength: 32
    Lanes: 4
    MemoryCost: 131072
    Password: null
    Salt: null
    Secret: null
    SecureArrayCall: {Isopoh.Cryptography.SecureArray.DefaultWindowsSecureArrayCall}
    Threads: 4
    TimeCost: 3
    Type: HybridAddressing
    Version: Nineteen

The exception states the following: Failed to allocate 16777216-byte Argon2 block array, memory cost 131072, lane count 4.

The exception occurs sporadically but it's not comprehensible in which situation. Since it is an x86 application I thought it's about the memory consumption of my application but i've doublechecked this - it's just around 600MB. If I'm going to decrease the memory cost at some point it works.

nukeme1 commented 2 years ago

I have also noticed this issue using a different set of configurations:

       var res = new Argon2Config
        {
            Type = Argon2Type.DataIndependentAddressing,
            Password = Encoding.UTF8.GetBytes(GetValidStringFromInput(input)),
            Salt = DeriveSaltFromContent(input, argonVer),
            ClearPassword = true,
            ClearSecret = true,
        };

with the usage example:

      SecureArray<byte> res = null;
        using (var hasher = new Argon2(config))
            res = hasher.Hash();`