authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2021-07-22 01:27:42+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-07-22 01:27:42+02:00
log680fa880d63daa6058a084f1c107162e40e18aa8
treeb5f8ceee481384db3ed12e97ecf19bb49179c058
parent8d0671157cdf8bc8b89d047138b42227420a5388
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std.crypto: handle the top bit in 25519.field.fromBytes64() (#9435)

The only known use case for this is the hash-to-curve operation where the top bit is always cleared. But the function is public, so let's make it work as one would expect in the general case. Also fix the comment by the way.

1 files changed, 2 insertions(+), 2 deletions(-)

lib/std/crypto/25519/field.zig+2-2
......@@ -93,7 +93,7 @@ pub const Fe = struct {
9393 return s;
9494 }
9595
96 /// Map a 64-bit big endian string into a field element
96 /// Map a 64 bytes big endian string into a field element
9797 pub fn fromBytes64(s: [64]u8) Fe {
9898 var fl: [32]u8 = undefined;
9999 var gl: [32]u8 = undefined;
......@@ -106,7 +106,7 @@ pub const Fe = struct {
106106 gl[31] &= 0x7f;
107107 var fe_f = fromBytes(fl);
108108 const fe_g = fromBytes(gl);
109 fe_f.limbs[0] += (s[32] >> 7) * 19;
109 fe_f.limbs[0] += (s[32] >> 7) * 19 + @as(u10, s[0] >> 7) * 722;
110110 i = 0;
111111 while (i < 5) : (i += 1) {
112112 fe_f.limbs[i] += 38 * fe_g.limbs[i];