Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ed25519: Add key-blinding function #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Chaos.NaCl/Ed25519.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,29 @@ public static void KeyExchange(ArraySegment<byte> sharedKey, ArraySegment<byte>
FieldOperations.fe_tobytes(sharedKey.Array, sharedKey.Offset, ref sharedMontgomeryX);
MontgomeryCurve25519.KeyExchangeOutputHashNaCl(sharedKey.Array, sharedKey.Offset);
}

public static bool CalculateBlindedPublicKey(byte[] publicKey, byte[] blindingFator, out byte[] output)
{
if (publicKey is null)
throw new ArgumentNullException("publicKey.Array");
if (publicKey.Length != PublicKeySizeInBytes)
throw new ArgumentException("publicKey.Count != 32");

output = new byte[PublicKeySizeInBytes];

byte[] zeros = new byte[PublicKeySizeInBytes];
byte[] pkCopy = new byte[PublicKeySizeInBytes];
Array.Copy(publicKey, pkCopy, PublicKeySizeInBytes);
pkCopy[31] ^= (1 << 7);

if (GroupOperations.ge_frombytes_negate_vartime(out var A, pkCopy, 0) != 0)
return false;

/* There isn't a regular ge_scalarmult -- we have to do tweak*A + zero*B. */
GroupOperations.ge_double_scalarmult_vartime(out var Aprime, blindingFator, ref A, zeros);
GroupOperations.ge_tobytes(output,0, ref Aprime);

return true;
}
}
}