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 andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-08-31 13:31:06-07:00
logb8a77f3d5931e0bf4f3c5544957dd36380367a43
tree0983b03954e8020379656b8d3201173b8d9f35f3
parentd4e22e3eb668968fa30f25c382b97629902f0bf8

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];