Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fp12_tower.c: add blst_bendian_from_fp12. #102

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/blst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,8 @@ class PT {
PT* mul(const PT& p) { blst_fp12_mul(&value, &value, p); return this; }
PT* final_exp() { blst_final_exp(&value, &value); return this; }
bool in_group() const { return blst_fp12_in_group(&value); }
void to_bendian(byte out[48*12]) const
{ blst_bendian_from_fp12(out, &value); }

static bool finalverify(const PT& gt1, const PT& gt2)
{ return blst_fp12_finalverify(gt1, gt2); }
Expand Down
1 change: 1 addition & 0 deletions bindings/blst_aux.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ void blst_p2_unchecked_mult(blst_p2 *out, const blst_p2 *p, const byte *scalar,
void blst_pairing_raw_aggregate(blst_pairing *ctx, const blst_p2_affine *q,
const blst_p1_affine *p);
blst_fp12 *blst_pairing_as_fp12(blst_pairing *ctx);
void blst_bendian_from_fp12(byte out[48*12], const blst_fp12 *a);

#endif
6 changes: 6 additions & 0 deletions bindings/go/blst.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ func (pt *Fp12) InGroup() bool {
return bool(C.blst_fp12_in_group(pt))
}

func (pt *Fp12) ToBendian() []byte {
var out [BLST_FP_BYTES * 12]byte
C.blst_bendian_from_fp12((*C.byte)(&out[0]), pt)
return out[:]
}

//
// MIN-PK
//
Expand Down
6 changes: 6 additions & 0 deletions bindings/go/blst.tgo
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,9 @@ func (pt *Fp12) FinalExp() {
func (pt *Fp12) InGroup() bool {
return bool(C.blst_fp12_in_group(pt))
}

func (pt *Fp12) ToBendian() []byte {
var out [BLST_FP_BYTES*12]byte
C.blst_bendian_from_fp12((*C.byte)(&out[0]), pt)
return out[:]
}
5 changes: 4 additions & 1 deletion bindings/rust/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ macro_rules! offsetof {
}
};
}
/* automatically generated by rust-bindgen 0.59.1 */
/* automatically generated by rust-bindgen 0.59.2 */

#[repr(u32)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -1293,3 +1293,6 @@ extern "C" {
extern "C" {
pub fn blst_pairing_as_fp12(ctx: *mut blst_pairing) -> *mut blst_fp12;
}
extern "C" {
pub fn blst_bendian_from_fp12(out: *mut byte, a: *const blst_fp12);
}
8 changes: 8 additions & 0 deletions bindings/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ impl blst_fp12 {
pub fn finalverify(a: &Self, b: &Self) -> bool {
unsafe { blst_fp12_finalverify(a, b) }
}

pub fn to_bendian(&self) -> [u8; 48 * 12] {
let mut out = MaybeUninit::<[u8; 48 * 12]>::uninit();
unsafe {
blst_bendian_from_fp12(out.as_mut_ptr() as *mut u8, self);
out.assume_init()
}
}
}

impl blst_scalar {
Expand Down
1 change: 1 addition & 0 deletions build/win64/blst.def
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,5 @@ EXPORTS
blst_p2_unchecked_mult
blst_pairing_raw_aggregate
blst_pairing_as_fp12
blst_bendian_from_fp12

15 changes: 15 additions & 0 deletions src/fp12_tower.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,18 @@ int blst_fp12_is_one(const vec384fp12 a)

const vec384fp12 *blst_fp12_one(void)
{ return (const vec384fp12 *)BLS12_381_Rx.p12; }

void blst_bendian_from_fp12(unsigned char ret[48*12], const vec384fp12 a)
{
size_t i, j;
vec384 out;

for (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) {
from_fp(out, a[j][i][0]);
be_bytes_from_limbs(ret, out, sizeof(vec384)); ret += 48;
from_fp(out, a[j][i][1]);
be_bytes_from_limbs(ret, out, sizeof(vec384)); ret += 48;
}
}
}