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