< Summary

Line coverage
98%
Covered lines: 54
Uncovered lines: 1
Coverable lines: 55
Total lines: 184
Line coverage: 98.1%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
File 1: crypto_sign_keypair(...)100%2100%
File 2: crypto_sign_verify(...)50%495%
File 3: crypto_sign2(...)100%1100%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Chaos.NaCl\Internal\Ed25519Ref10\keypair.cs

#LineLine coverage
 1using System;
 2
 3namespace Renci.SshNet.Security.Chaos.NaCl.Internal.Ed25519Ref10
 4{
 5    internal static partial class Ed25519Operations
 6    {
 7        internal static void crypto_sign_keypair(byte[] pk, int pkoffset, byte[] sk, int skoffset, byte[] seed, int seed
 78        {
 9            GroupElementP3 A;
 10            int i;
 11
 712            Array.Copy(seed, seedoffset, sk, skoffset, 32);
 713            byte[] h = Sha512.Hash(sk, skoffset, 32);//ToDo: Remove alloc
 714            ScalarOperations.sc_clamp(h, 0);
 15
 716            GroupOperations.ge_scalarmult_base(out A, h, 0);
 717            GroupOperations.ge_p3_tobytes(pk, pkoffset, ref A);
 18
 68619            for (i = 0; i < 32; ++i) sk[skoffset + 32 + i] = pk[pkoffset + i];
 720            CryptoBytes.Wipe(h);
 721        }
 22    }
 23}

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Chaos.NaCl\Internal\Ed25519Ref10\open.cs

#LineLine coverage
 1using System;
 2
 3namespace Renci.SshNet.Security.Chaos.NaCl.Internal.Ed25519Ref10
 4{
 5    internal static partial class Ed25519Operations
 6    {
 7        // Original crypto_sign_open, for reference only
 8        /*internal static int crypto_sign_open(
 9          byte[] m, out int mlen,
 10          byte[] sm, int smlen,
 11          byte[] pk)
 12        {
 13            byte[] h = new byte[64];
 14            byte[] checkr = new byte[32];
 15            GroupElementP3 A;
 16            GroupElementP2 R;
 17            int i;
 18
 19            mlen = -1;
 20            if (smlen < 64) return -1;
 21            if ((sm[63] & 224) != 0) return -1;
 22            if (GroupOperations.ge_frombytes_negate_vartime(out A, pk, 0) != 0) return -1;
 23
 24            for (i = 0; i < smlen; ++i) m[i] = sm[i];
 25            for (i = 0; i < 32; ++i) m[32 + i] = pk[i];
 26            Sha512BclWrapper.crypto_hash_sha512(h, m, 0, smlen);
 27            ScalarOperations.sc_reduce(h);
 28
 29            var sm32 = new byte[32];
 30            Array.Copy(sm, 32, sm32, 0, 32);
 31            GroupOperations.ge_double_scalarmult_vartime(out R, h, ref A, sm32);
 32            GroupOperations.ge_tobytes(checkr, 0, ref R);
 33            if (Helpers.crypto_verify_32(checkr, sm) != 0)
 34            {
 35                for (i = 0; i < smlen; ++i)
 36                    m[i] = 0;
 37                return -1;
 38            }
 39
 40            for (i = 0; i < smlen - 64; ++i)
 41                m[i] = sm[64 + i];
 42            for (i = smlen - 64; i < smlen; ++i)
 43                m[i] = 0;
 44            mlen = smlen - 64;
 45            return 0;
 46        }*/
 47
 48        internal static bool crypto_sign_verify(
 49            byte[] sig, int sigoffset,
 50            byte[] m, int moffset, int mlen,
 51            byte[] pk, int pkoffset)
 352        {
 53            byte[] h;
 354            byte[] checkr = new byte[32];
 55            GroupElementP3 A;
 56            GroupElementP2 R;
 57
 358            if ((sig[sigoffset + 63] & 224) != 0) return false;
 359            if (GroupOperations.ge_frombytes_negate_vartime(out A, pk, pkoffset) != 0)
 060                return false;
 61
 362            var hasher = new Sha512();
 363            hasher.Update(sig, sigoffset, 32);
 364            hasher.Update(pk, pkoffset, 32);
 365            hasher.Update(m, moffset, mlen);
 366            h = hasher.Finish();
 67
 368            ScalarOperations.sc_reduce(h);
 69
 370            var sm32 = new byte[32];//todo: remove allocation
 371            Array.Copy(sig, sigoffset + 32, sm32, 0, 32);
 372            GroupOperations.ge_double_scalarmult_vartime(out R, h, ref A, sm32);
 373            GroupOperations.ge_tobytes(checkr, 0, ref R);
 374            var result = CryptoBytes.ConstantTimeEquals(checkr, 0, sig, sigoffset, 32);
 375            CryptoBytes.Wipe(h);
 376            CryptoBytes.Wipe(checkr);
 377            return result;
 378        }
 79    }
 80}

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Chaos.NaCl\Internal\Ed25519Ref10\sign.cs

#LineLine coverage
 1using System;
 2
 3namespace Renci.SshNet.Security.Chaos.NaCl.Internal.Ed25519Ref10
 4{
 5  internal static partial class Ed25519Operations
 6  {
 7    /*internal static void crypto_sign(
 8      byte[] sm, out int smlen,
 9       byte[] m, int mlen,
 10       byte[] sk
 11    )
 12    {
 13      byte[] az = new byte[64];
 14      byte[] r = new byte[64];
 15      byte[] hram = new byte[64];
 16      GroupElementP3 R;
 17      int i;
 18
 19      Helpers.crypto_hash_sha512(az, sk, 0, 32);
 20      az[0] &= 248;
 21      az[31] &= 63;
 22      az[31] |= 64;
 23
 24      smlen = mlen + 64;
 25      for (i = 0; i < mlen; ++i) sm[64 + i] = m[i];
 26      for (i = 0; i < 32; ++i) sm[32 + i] = az[32 + i];
 27      Helpers.crypto_hash_sha512(r, sm, 32, mlen + 32);
 28      for (i = 0; i < 32; ++i) sm[32 + i] = sk[32 + i];
 29
 30      ScalarOperations.sc_reduce(r);
 31      GroupOperations.ge_scalarmult_base(out R, r, 0);
 32      GroupOperations.ge_p3_tobytes(sm, 0, ref R);
 33
 34      Helpers.crypto_hash_sha512(hram, sm, 0, mlen + 64);
 35      ScalarOperations.sc_reduce(hram);
 36      var sm32 = new byte[32];
 37      Array.Copy(sm, 32, sm32, 0, 32);
 38      ScalarOperations.sc_muladd(sm32, hram, az, r);
 39      Array.Copy(sm32, 0, sm, 32, 32);
 40    }*/
 41
 42    internal static void crypto_sign2(
 43      byte[] sig, int sigoffset,
 44      byte[] m, int moffset, int mlen,
 45      byte[] sk, int skoffset)
 146    {
 47      byte[] az;
 48      byte[] r;
 49      byte[] hram;
 50      GroupElementP3 R;
 151        var hasher = new Sha512();
 152      {
 153                hasher.Update(sk, skoffset, 32);
 154          az = hasher.Finish();
 155          ScalarOperations.sc_clamp(az, 0);
 56
 157          hasher.Init();
 158        hasher.Update(az, 32, 32);
 159        hasher.Update(m, moffset, mlen);
 160        r = hasher.Finish();
 61
 162        ScalarOperations.sc_reduce(r);
 163        GroupOperations.ge_scalarmult_base(out R, r, 0);
 164        GroupOperations.ge_p3_tobytes(sig, sigoffset, ref R);
 65
 166        hasher.Init();
 167        hasher.Update(sig, sigoffset, 32);
 168        hasher.Update(sk, skoffset + 32, 32);
 169        hasher.Update(m, moffset, mlen);
 170        hram = hasher.Finish();
 71
 172        ScalarOperations.sc_reduce(hram);
 173        var s = new byte[32];//todo: remove allocation
 174        Array.Copy(sig, sigoffset + 32, s, 0, 32);
 175        ScalarOperations.sc_muladd(s, hram, az, r);
 176        Array.Copy(s, 0, sig, sigoffset + 32, 32);
 177        CryptoBytes.Wipe(s);
 178      }
 179    }
 80  }
 81}