Skip to content

Commit 10463fe

Browse files
committed
exports.c: add blst_blst_from_{lb}e_bytes.
1 parent 097818a commit 10463fe

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

bindings/blst_aux.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ size_t blst_p2_sizeof(void);
110110
size_t blst_p2_affine_sizeof(void);
111111
size_t blst_fp12_sizeof(void);
112112

113+
void blst_fp_from_le_bytes(blst_fp *ret, const byte *in, size_t len);
114+
void blst_fp_from_be_bytes(blst_fp *ret, const byte *in, size_t len);
115+
113116
/*
114117
* Single-shot SHA-256 hash function.
115118
*/

src/exports.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,43 @@ int blst_scalar_from_be_bytes(pow256 out, const unsigned char *bytes, size_t n)
550550
return (int)(ret^1);
551551
}
552552

553+
void blst_fp_from_le_bytes(vec384 out, const unsigned char *bytes, size_t n)
554+
{
555+
size_t rem = (n - 1) % 48 + 1;
556+
vec384 digit;
557+
558+
vec_zero(out, sizeof(vec384));
559+
560+
n -= rem;
561+
limbs_from_le_bytes(out, bytes += n, rem);
562+
mul_mont_384(out, BLS12_381_RR, out, BLS12_381_P, p0);
563+
564+
while (n) {
565+
limbs_from_le_bytes(digit, bytes -= 48, 48);
566+
add_mod_384(out, out, digit, BLS12_381_P);
567+
mul_mont_384(out, BLS12_381_RR, out, BLS12_381_P, p0);
568+
n -= 48;
569+
}
570+
}
571+
572+
void blst_fp_from_be_bytes(vec384 out, const unsigned char *bytes, size_t n)
573+
{
574+
size_t rem = (n - 1) % 48 + 1;
575+
vec384 digit;
576+
577+
vec_zero(out, sizeof(vec384));
578+
579+
limbs_from_be_bytes(out, bytes, rem);
580+
mul_mont_384(out, BLS12_381_RR, out, BLS12_381_P, p0);
581+
582+
while (n -= rem) {
583+
limbs_from_be_bytes(digit, bytes += rem, 48);
584+
add_mod_384(out, out, digit, BLS12_381_P);
585+
mul_mont_384(out, BLS12_381_RR, out, BLS12_381_P, p0);
586+
rem = 48;
587+
}
588+
}
589+
553590
/*
554591
* Single-short SHA-256 hash function.
555592
*/

0 commit comments

Comments
 (0)