Skip to content

Commit

Permalink
More robust GMP backends.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Dec 30, 2024
1 parent c48ba4f commit 782be63
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/low/gmp-sec/relic_bn_shift_low.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RELIC is an Efficient LIbrary for Cryptography
* Copyright (c) 2015 RELIC Authors
* Copyright (c) 2009 RELIC Authors
*
* This file is part of RELIC. RELIC is legal property of its developers,
* whose names are not listed here. Please refer to the COPYRIGHT file
Expand Down Expand Up @@ -34,8 +34,10 @@
#include <stdio.h>
#include <string.h>

#include "relic_dv.h"
#include "relic_bn.h"
#include "relic_bn_low.h"
#include "relic_alloc.h"

/*============================================================================*/
/* Public definitions */
Expand All @@ -46,15 +48,25 @@ dig_t bn_lsh1_low(dig_t *c, const dig_t *a, size_t size) {
}

dig_t bn_lshb_low(dig_t *c, const dig_t *a, size_t size, uint_t bits) {
return mpn_lshift(c, a, size, bits);
dig_t carry, *t = (dig_t *)RLC_ALLOCA(dig_t, size);
carry = mpn_lshift(t, a, size, bits);
dv_copy(c, a, size);
dv_copy_sec(c, t, size, bits > 0);
RLC_FREE(t);
return RLC_SEL(0, carry, bits > 0);
}

dig_t bn_rsh1_low(dig_t *c, const dig_t *a, size_t size) {
return mpn_rshift(c, a, size, 1);
}

dig_t bn_rshb_low(dig_t *c, const dig_t *a, size_t size, uint_t bits) {
return mpn_rshift(c, a, size, bits);
dig_t carry, *t = (dig_t *)RLC_ALLOCA(dig_t, size);
carry = mpn_rshift(t, a, size, bits);
dv_copy(c, a, size);
dv_copy_sec(c, t, size, bits > 0);
RLC_FREE(t);
return RLC_SEL(0, carry, bits > 0);
}

dig_t bn_rshs_low(dig_t *c, const dig_t *a, size_t size, uint_t bits) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <stdio.h>
#include <string.h>

#include "relic_dv.h"
#include "relic_bn.h"
#include "relic_bn_low.h"

Expand All @@ -46,15 +47,27 @@ dig_t bn_lsh1_low(dig_t *c, const dig_t *a, size_t size) {
}

dig_t bn_lshb_low(dig_t *c, const dig_t *a, size_t size, uint_t bits) {
return mpn_lshift(c, a, size, bits);
dig_t carry = 0;
if (bits > 0) {
carry = mpn_lshift(c, a, size, bits);
} else {
dv_copy(c, a, size);
}
return carry;
}

dig_t bn_rsh1_low(dig_t *c, const dig_t *a, size_t size) {
return mpn_rshift(c, a, size, 1);
}

dig_t bn_rshb_low(dig_t *c, const dig_t *a, size_t size, uint_t bits) {
return mpn_rshift(c, a, size, bits);
dig_t carry = 0;
if (bits > 0) {
carry = mpn_rshift(c, a, size, bits);
} else {
dv_copy(c, a, size);
}
return carry;
}

dig_t bn_rshs_low(dig_t *c, const dig_t *a, size_t size, uint_t bits) {
Expand Down

0 comments on commit 782be63

Please sign in to comment.