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 {...@@ -93,7 +93,7 @@ pub const Fe = struct {
93 return s;93 return s;
94 }94 }
9595
96 /// Map a 64-bit big endian string into a field element96 /// Map a 64 bytes big endian string into a field element
97 pub fn fromBytes64(s: [64]u8) Fe {97 pub fn fromBytes64(s: [64]u8) Fe {
98 var fl: [32]u8 = undefined;98 var fl: [32]u8 = undefined;
99 var gl: [32]u8 = undefined;99 var gl: [32]u8 = undefined;
...@@ -106,7 +106,7 @@ pub const Fe = struct {...@@ -106,7 +106,7 @@ pub const Fe = struct {
106 gl[31] &= 0x7f;106 gl[31] &= 0x7f;
107 var fe_f = fromBytes(fl);107 var fe_f = fromBytes(fl);
108 const fe_g = fromBytes(gl);108 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;
110 i = 0;110 i = 0;
111 while (i < 5) : (i += 1) {111 while (i < 5) : (i += 1) {
112 fe_f.limbs[i] += 38 * fe_g.limbs[i];112 fe_f.limbs[i] += 38 * fe_g.limbs[i];