-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retagging version 0.3.1 for release.
- Loading branch information
Showing
19 changed files
with
2,628 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
set(ARITH_LIBS "gmp") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2007 Project RELIC | ||
* | ||
* 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. | ||
* | ||
* RELIC is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* RELIC is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with RELIC. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* | ||
* Useful macros for binary field arithmetic. | ||
* | ||
* @version $Id$ | ||
* @ingroup fb | ||
*/ | ||
|
||
#define PSHUFB(A, B) _mm_shuffle_epi8(A, B); | ||
#define SHL64(A, B) _mm_slli_epi64(A, B) | ||
#define SHR64(A, B) _mm_srli_epi64(A, B) | ||
#define XOR(A, B) _mm_xor_si128(A, B) | ||
#define SHL8(A, B) _mm_slli_si128(A, B) | ||
#define SHR8(A, B) _mm_srli_si128(A, B) | ||
#define AND(A, B) _mm_and_si128(A, B) | ||
|
||
#define MUL(ma, mb) \ | ||
t0 = _mm_clmulepi64_si128(ma, mb, 0x00);\ | ||
t1 = _mm_clmulepi64_si128(ma, mb, 0x11);\ | ||
t2 = XOR(SHR8(ma, 8), ma);\ | ||
t3 = XOR(SHR8(mb, 8), mb);\ | ||
t2 = _mm_clmulepi64_si128(t2, t3, 0x00);\ | ||
t2 = XOR(t2, t0);\ | ||
t2 = XOR(t2, t1);\ | ||
t3 = SHR8(t2, 8);\ | ||
t2 = SHL8(t2, 8);\ | ||
t0 = XOR(t0, t2);\ | ||
t1 = XOR(t1, t3);\ | ||
|
||
#define MULDXS(ma, mb) \ | ||
t0 = _mm_clmulepi64_si128(ma, mb, 0x00);\ | ||
t2 = _mm_clmulepi64_si128(ma, mb, 0x01);\ | ||
t1 = SHR8(t2, 8);\ | ||
t2 = SHL8(t2, 8);\ | ||
t0 = XOR(t0, t2);\ | ||
|
||
#define MULSXD(ma, mb) \ | ||
MULDXS(mb, ma) | ||
|
||
#define RED251(t,m1,m0)\ | ||
t0 = _mm_slli_si128(t,8);\ | ||
t1 = _mm_srli_si128(t,8);\ | ||
m1 = _mm_xor_si128(m1,_mm_srli_epi64(t1,59));\ | ||
m1 = _mm_xor_si128(m1,_mm_srli_epi64(t1,57));\ | ||
m1 = _mm_xor_si128(m1,_mm_srli_epi64(t1,55));\ | ||
m1 = _mm_xor_si128(m1,_mm_srli_epi64(t1,52));\ | ||
m0 = _mm_xor_si128(m0,_mm_srli_epi64(t0,59));\ | ||
m0 = _mm_xor_si128(m0,_mm_srli_epi64(t0,57));\ | ||
m0 = _mm_xor_si128(m0,_mm_srli_epi64(t0,55));\ | ||
m0 = _mm_xor_si128(m0,_mm_srli_epi64(t0,52));\ | ||
t0 = _mm_srli_si128(t0,8);\ | ||
t1 = _mm_slli_si128(t1,8);\ | ||
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t0,5));\ | ||
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t0,7));\ | ||
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t0,9));\ | ||
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t0,12));\ | ||
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t1,5));\ | ||
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t1,7));\ | ||
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t1,9));\ | ||
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t1,12)); | ||
|
||
#define REDUCE() \ | ||
RED251(m3,m2,m1); \ | ||
RED251(m2,m1,m0); \ | ||
m8 = _mm_srli_si128(m1,8); \ | ||
m9 = _mm_srli_epi64(m8,59); \ | ||
m9 = _mm_slli_epi64(m9,59); \ | ||
m0 = _mm_xor_si128(m0,_mm_srli_epi64(m9,59)); \ | ||
m0 = _mm_xor_si128(m0,_mm_srli_epi64(m9,57)); \ | ||
m0 = _mm_xor_si128(m0,_mm_srli_epi64(m9,55)); \ | ||
m0 = _mm_xor_si128(m0,_mm_srli_epi64(m9,52)); \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* RELIC is an Efficient LIbrary for Cryptography | ||
* Copyright (C) 2007-2011 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 | ||
* for contact information. | ||
* | ||
* RELIC is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* RELIC is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with RELIC. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* | ||
* Implementation of the low-level multiple precision division functions. | ||
* | ||
* @version $Id: relic_bn_div_low.c 677 2011-03-05 22:19:43Z dfaranha $ | ||
* @ingroup bn | ||
*/ | ||
|
||
#include <gmp.h> | ||
|
||
#include "relic_bn.h" | ||
#include "relic_bn_low.h" | ||
|
||
/*============================================================================*/ | ||
/* Public definitions */ | ||
/*============================================================================*/ | ||
|
||
void bn_divn_low(dig_t *c, dig_t *d, dig_t *a, int sa, dig_t *b, int sb) { | ||
mpn_tdiv_qr(c, d, 0, a, sa, b, sb); | ||
} | ||
|
||
void bn_div1_low(dig_t *c, dig_t *d, dig_t *a, int size, dig_t b) { | ||
*d = mpn_divrem_1(c, 0, a, size, b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* RELIC is an Efficient LIbrary for Cryptography | ||
* Copyright (C) 2007-2011 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 | ||
* for contact information. | ||
* | ||
* RELIC is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* RELIC is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with RELIC. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* | ||
* Implementation of the low-level multiple precision integer modular reduction | ||
* functions. | ||
* | ||
* @version $Id: relic_bn_mod_low.c 677 2011-03-05 22:19:43Z dfaranha $ | ||
* @ingroup bn | ||
*/ | ||
|
||
#include <gmp.h> | ||
#include <string.h> | ||
|
||
#include "relic_bn.h" | ||
#include "relic_bn_low.h" | ||
#include "relic_util.h" | ||
|
||
/*============================================================================*/ | ||
/* Public definitions */ | ||
/*============================================================================*/ | ||
|
||
void bn_modn_low(dig_t *c, dig_t *a, int sa, dig_t *m, int sm, dig_t u) { | ||
int i; | ||
dig_t r, carry, *tmpc; | ||
|
||
tmpc = c; | ||
|
||
for (i = 0; i < sa; i++, tmpc++, a++) { | ||
*tmpc = *a; | ||
} | ||
|
||
tmpc = c; | ||
|
||
for (i = 0; i < sm; i++, tmpc++) { | ||
r = (dig_t)(*tmpc * u); | ||
carry = mpn_addmul_1(tmpc, m, sm, r); | ||
mpn_add_1(tmpc + sm, tmpc + sm, sm - i + 1, carry); | ||
} | ||
bn_rshd_low(c, c, 2 * sm + 1, sm); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* RELIC is an Efficient LIbrary for Cryptography | ||
* Copyright (C) 2007-2011 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 | ||
* for contact information. | ||
* | ||
* RELIC is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* RELIC is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with RELIC. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* | ||
* Implementation of the multiple precision integer arithmetic multiplication | ||
* functions. | ||
* | ||
* @version $Id: relic_bn_mul_low.c 976 2012-01-07 02:21:45Z dfaranha $ | ||
* @ingroup bn | ||
*/ | ||
|
||
#include <gmp.h> | ||
|
||
#include "relic_bn.h" | ||
#include "relic_bn_low.h" | ||
#include "relic_util.h" | ||
|
||
/*============================================================================*/ | ||
/* Public definitions */ | ||
/*============================================================================*/ | ||
|
||
dig_t bn_muladd_low(dig_t *c, dig_t *a, dig_t digit, int size) { | ||
return mpn_addmul_1(c, a, size, digit); | ||
} | ||
|
||
dig_t bn_mul1_low(dig_t *c, dig_t *a, dig_t digit, int size) { | ||
return mpn_mul_1(c, a, size, digit); | ||
} | ||
|
||
void bn_muln_low(dig_t *c, dig_t *a, dig_t *b, int size) { | ||
mpn_mul_n(c, a, b, size); | ||
} | ||
|
||
void bn_muld_low(dig_t *c, dig_t *a, int sizea, dig_t *b, int sizeb, | ||
int low, int high) { | ||
(void) low; | ||
(void) high; | ||
mpn_mul(c, a, sizea, b, sizeb); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* RELIC is an Efficient LIbrary for Cryptography | ||
* Copyright (C) 2007-2011 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 | ||
* for contact information. | ||
* | ||
* RELIC is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* RELIC is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with RELIC. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @file | ||
* | ||
* Implementation of the multiple precision integer arithmetic multiplication | ||
* functions. | ||
* | ||
* @version $Id: relic_bn_sqr_low.c 677 2011-03-05 22:19:43Z dfaranha $ | ||
* @ingroup bn | ||
*/ | ||
|
||
#include <gmp.h> | ||
|
||
#include "relic_bn.h" | ||
#include "relic_bn_low.h" | ||
#include "relic_util.h" | ||
|
||
/*============================================================================*/ | ||
/* Public definitions */ | ||
/*============================================================================*/ | ||
|
||
void bn_sqradd_low(dig_t *c, dig_t *a, int size) { | ||
dig_t carry; | ||
dig_t digit; | ||
|
||
digit = *a; | ||
|
||
carry = mpn_addmul_1(c, a, size, digit); | ||
mpn_add_1(c+size, c+size, size, carry); | ||
if (size - 1 > 0) { | ||
carry = mpn_addmul_1(c+1, a+1, size-1, digit); | ||
mpn_add_1(c+size, c+size, size, carry); | ||
} | ||
} | ||
|
||
void bn_sqrn_low(dig_t *c, dig_t *a, int size) { | ||
mpn_mul_n(c, a, a, size); | ||
} |
Oops, something went wrong.