# < Summary

Information

Class: | Renci.SshNet.Security.Chaos.NaCl.Internal.Ed25519Ref10.Ed25519Operations
Assembly: | Renci.SshNet
File(s): | File 1: \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Chaos.NaCl\Internal\Ed25519Ref10\keypair.cs File 2: \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Chaos.NaCl\Internal\Ed25519Ref10\open.cs File 3: \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Chaos.NaCl\Internal\Ed25519Ref10\sign.cs

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

Method | Branch coverage | Cyclomatic complexity | Line coverage
--- | --- | --- | ---
File 1: crypto_sign_keypair(...) | 100% | 2 | 100%
File 2: crypto_sign_verify(...) | 50% | 4 | 95%
File 3: crypto_sign2(...) | 100% | 1 | 100%

# File(s)

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

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | ``
|  | `3` |  | `namespace 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`
| 7 | `8` |  | `{`
|  | `9` |  | `GroupElementP3 A;`
|  | `10` |  | `int i;`
|  | `11` |  | ``
| 7 | `12` |  | `Array.Copy(seed, seedoffset, sk, skoffset, 32);`
| 7 | `13` |  | `byte[] h = Sha512.Hash(sk, skoffset, 32);//ToDo: Remove alloc`
| 7 | `14` |  | `ScalarOperations.sc_clamp(h, 0);`
|  | `15` |  | ``
| 7 | `16` |  | `GroupOperations.ge_scalarmult_base(out A, h, 0);`
| 7 | `17` |  | `GroupOperations.ge_p3_tobytes(pk, pkoffset, ref A);`
|  | `18` |  | ``
| 686 | `19` |  | `for (i = 0; i < 32; ++i) sk[skoffset + 32 + i] = pk[pkoffset + i];`
| 7 | `20` |  | `CryptoBytes.Wipe(h);`
| 7 | `21` |  | `}`
|  | `22` |  | `}`
|  | `23` |  | `}`

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

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | ``
|  | `3` |  | `namespace 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)`
| 3 | `52` |  | `{`
|  | `53` |  | `byte[] h;`
| 3 | `54` |  | `byte[] checkr = new byte[32];`
|  | `55` |  | `GroupElementP3 A;`
|  | `56` |  | `GroupElementP2 R;`
|  | `57` |  | ``
| 3 | `58` |  | `if ((sig[sigoffset + 63] & 224) != 0) return false;`
| 3 | `59` |  | `if (GroupOperations.ge_frombytes_negate_vartime(out A, pk, pkoffset) != 0)`
| 0 | `60` |  | `return false;`
|  | `61` |  | ``
| 3 | `62` |  | `var hasher = new Sha512();`
| 3 | `63` |  | `hasher.Update(sig, sigoffset, 32);`
| 3 | `64` |  | `hasher.Update(pk, pkoffset, 32);`
| 3 | `65` |  | `hasher.Update(m, moffset, mlen);`
| 3 | `66` |  | `h = hasher.Finish();`
|  | `67` |  | ``
| 3 | `68` |  | `ScalarOperations.sc_reduce(h);`
|  | `69` |  | ``
| 3 | `70` |  | `var sm32 = new byte[32];//todo: remove allocation`
| 3 | `71` |  | `Array.Copy(sig, sigoffset + 32, sm32, 0, 32);`
| 3 | `72` |  | `GroupOperations.ge_double_scalarmult_vartime(out R, h, ref A, sm32);`
| 3 | `73` |  | `GroupOperations.ge_tobytes(checkr, 0, ref R);`
| 3 | `74` |  | `var result = CryptoBytes.ConstantTimeEquals(checkr, 0, sig, sigoffset, 32);`
| 3 | `75` |  | `CryptoBytes.Wipe(h);`
| 3 | `76` |  | `CryptoBytes.Wipe(checkr);`
| 3 | `77` |  | `return result;`
| 3 | `78` |  | `}`
|  | `79` |  | `}`
|  | `80` |  | `}`

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

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | ``
|  | `3` |  | `namespace 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)`
| 1 | `46` |  | `{`
|  | `47` |  | `byte[] az;`
|  | `48` |  | `byte[] r;`
|  | `49` |  | `byte[] hram;`
|  | `50` |  | `GroupElementP3 R;`
| 1 | `51` |  | `var hasher = new Sha512();`
| 1 | `52` |  | `{`
| 1 | `53` |  | `hasher.Update(sk, skoffset, 32);`
| 1 | `54` |  | `az = hasher.Finish();`
| 1 | `55` |  | `ScalarOperations.sc_clamp(az, 0);`
|  | `56` |  | ``
| 1 | `57` |  | `hasher.Init();`
| 1 | `58` |  | `hasher.Update(az, 32, 32);`
| 1 | `59` |  | `hasher.Update(m, moffset, mlen);`
| 1 | `60` |  | `r = hasher.Finish();`
|  | `61` |  | ``
| 1 | `62` |  | `ScalarOperations.sc_reduce(r);`
| 1 | `63` |  | `GroupOperations.ge_scalarmult_base(out R, r, 0);`
| 1 | `64` |  | `GroupOperations.ge_p3_tobytes(sig, sigoffset, ref R);`
|  | `65` |  | ``
| 1 | `66` |  | `hasher.Init();`
| 1 | `67` |  | `hasher.Update(sig, sigoffset, 32);`
| 1 | `68` |  | `hasher.Update(sk, skoffset + 32, 32);`
| 1 | `69` |  | `hasher.Update(m, moffset, mlen);`
| 1 | `70` |  | `hram = hasher.Finish();`
|  | `71` |  | ``
| 1 | `72` |  | `ScalarOperations.sc_reduce(hram);`
| 1 | `73` |  | `var s = new byte[32];//todo: remove allocation`
| 1 | `74` |  | `Array.Copy(sig, sigoffset + 32, s, 0, 32);`
| 1 | `75` |  | `ScalarOperations.sc_muladd(s, hram, az, r);`
| 1 | `76` |  | `Array.Copy(s, 0, sig, sigoffset + 32, 32);`
| 1 | `77` |  | `CryptoBytes.Wipe(s);`
| 1 | `78` |  | `}`
| 1 | `79` |  | `}`
|  | `80` |  | `}`
|  | `81` |  | `}`

# Methods/Properties

crypto_sign_keypair(System.Byte[],System.Int32,System.Byte[],System.Int32,System.Byte[],System.Int32)
crypto_sign_verify(System.Byte[],System.Int32,System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
crypto_sign2(System.Byte[],System.Int32,System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)