public static void crypto_sign_prehashed( byte[] sig, byte[] m, int mlen, byte[] sk, byte[] pk ) { byte[] r, hram; GroupElementP3 R; var hasher = new Sha512(); { hasher.Init(); hasher.Update(sk, 32, 32); hasher.Update(m, 0, mlen); r = hasher.Finalize(); ScalarOperations.sc_reduce(r); GroupOperations.ge_scalarmult_base(out R, r, 0); GroupOperations.ge_p3_tobytes(sig, 0, ref R); hasher.Init(); hasher.Update(sig, 0, 32); hasher.Update(pk, 0, 32); hasher.Update(m, 0, mlen); hram = hasher.Finalize(); ScalarOperations.sc_reduce(hram); var s = new byte[32]; //todo: remove allocation Array.Copy(sig, 32, s, 0, 32); ScalarOperations.sc_muladd(s, hram, sk, r); Array.Copy(s, 0, sig, 32, 32); CryptoBytes.Wipe(s); } }
public static void crypto_sign_keypair_prehashed(byte[] pk, int pkoffset, byte[] sk, int skoffset) { GroupElementP3 A; GroupOperations.ge_scalarmult_base(out A, sk, skoffset); GroupOperations.ge_p3_tobytes(pk, pkoffset, ref A); }
public static void crypto_sign_keypair(byte[] pk, int pkoffset, byte[] sk, int skoffset, byte[] seed, int seedoffset) { GroupElementP3 A; int i; Array.Copy(seed, seedoffset, sk, skoffset, 32); byte[] h = Sha512.Hash(sk, skoffset, 32);//ToDo: Remove alloc ScalarOperations.sc_clamp(h, 0); GroupOperations.ge_scalarmult_base(out A, h, 0); GroupOperations.ge_p3_tobytes(pk, pkoffset, ref A); for (i = 0; i < 32; ++i) { sk[skoffset + 32 + i] = pk[pkoffset + i]; } CryptoBytes.Wipe(h); }
public static void crypto_sign( byte[] sig, int sigoffset, byte[] m, int moffset, int mlen, byte[] sk, int skoffset) { byte[] az, r, hram; GroupElementP3 R; var hasher = new Sha512(); { hasher.Update(sk, skoffset, 32); az = hasher.Finalize(); ScalarOperations.sc_clamp(az, 0); hasher.Init(); hasher.Update(az, 32, 32); hasher.Update(m, moffset, mlen); r = hasher.Finalize(); ScalarOperations.sc_reduce(r); GroupOperations.ge_scalarmult_base(out R, r, 0); GroupOperations.ge_p3_tobytes(sig, sigoffset, ref R); hasher.Init(); hasher.Update(sig, sigoffset, 32); hasher.Update(sk, skoffset + 32, 32); hasher.Update(m, moffset, mlen); hram = hasher.Finalize(); ScalarOperations.sc_reduce(hram); var s = new byte[32]; //todo: remove allocation Array.Copy(sig, sigoffset + 32, s, 0, 32); ScalarOperations.sc_muladd(s, hram, az, r); Array.Copy(s, 0, sig, sigoffset + 32, 32); CryptoBytes.Wipe(s); } }