Skip to content

Commit b944d72

Browse files
committed
Retagging version 0.3.1 for release.
1 parent 015bdcf commit b944d72

19 files changed

+2628
-5
lines changed

src/low/curve2251-sse/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set(ARITH_LIBS "gmp")

src/low/curve2251-sse/macros.h

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2007 Project RELIC
3+
*
4+
* This file is part of RELIC. RELIC is legal property of its developers,
5+
* whose names are not listed here. Please refer to the COPYRIGHT file.
6+
*
7+
* RELIC is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* RELIC is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with RELIC. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
/**
22+
* @file
23+
*
24+
* Useful macros for binary field arithmetic.
25+
*
26+
* @version $Id$
27+
* @ingroup fb
28+
*/
29+
30+
#define PSHUFB(A, B) _mm_shuffle_epi8(A, B);
31+
#define SHL64(A, B) _mm_slli_epi64(A, B)
32+
#define SHR64(A, B) _mm_srli_epi64(A, B)
33+
#define XOR(A, B) _mm_xor_si128(A, B)
34+
#define SHL8(A, B) _mm_slli_si128(A, B)
35+
#define SHR8(A, B) _mm_srli_si128(A, B)
36+
#define AND(A, B) _mm_and_si128(A, B)
37+
38+
#define MUL(ma, mb) \
39+
t0 = _mm_clmulepi64_si128(ma, mb, 0x00);\
40+
t1 = _mm_clmulepi64_si128(ma, mb, 0x11);\
41+
t2 = XOR(SHR8(ma, 8), ma);\
42+
t3 = XOR(SHR8(mb, 8), mb);\
43+
t2 = _mm_clmulepi64_si128(t2, t3, 0x00);\
44+
t2 = XOR(t2, t0);\
45+
t2 = XOR(t2, t1);\
46+
t3 = SHR8(t2, 8);\
47+
t2 = SHL8(t2, 8);\
48+
t0 = XOR(t0, t2);\
49+
t1 = XOR(t1, t3);\
50+
51+
#define MULDXS(ma, mb) \
52+
t0 = _mm_clmulepi64_si128(ma, mb, 0x00);\
53+
t2 = _mm_clmulepi64_si128(ma, mb, 0x01);\
54+
t1 = SHR8(t2, 8);\
55+
t2 = SHL8(t2, 8);\
56+
t0 = XOR(t0, t2);\
57+
58+
#define MULSXD(ma, mb) \
59+
MULDXS(mb, ma)
60+
61+
#define RED251(t,m1,m0)\
62+
t0 = _mm_slli_si128(t,8);\
63+
t1 = _mm_srli_si128(t,8);\
64+
m1 = _mm_xor_si128(m1,_mm_srli_epi64(t1,59));\
65+
m1 = _mm_xor_si128(m1,_mm_srli_epi64(t1,57));\
66+
m1 = _mm_xor_si128(m1,_mm_srli_epi64(t1,55));\
67+
m1 = _mm_xor_si128(m1,_mm_srli_epi64(t1,52));\
68+
m0 = _mm_xor_si128(m0,_mm_srli_epi64(t0,59));\
69+
m0 = _mm_xor_si128(m0,_mm_srli_epi64(t0,57));\
70+
m0 = _mm_xor_si128(m0,_mm_srli_epi64(t0,55));\
71+
m0 = _mm_xor_si128(m0,_mm_srli_epi64(t0,52));\
72+
t0 = _mm_srli_si128(t0,8);\
73+
t1 = _mm_slli_si128(t1,8);\
74+
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t0,5));\
75+
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t0,7));\
76+
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t0,9));\
77+
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t0,12));\
78+
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t1,5));\
79+
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t1,7));\
80+
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t1,9));\
81+
m0 = _mm_xor_si128(m0,_mm_slli_epi64(t1,12));
82+
83+
#define REDUCE() \
84+
RED251(m3,m2,m1); \
85+
RED251(m2,m1,m0); \
86+
m8 = _mm_srli_si128(m1,8); \
87+
m9 = _mm_srli_epi64(m8,59); \
88+
m9 = _mm_slli_epi64(m9,59); \
89+
m0 = _mm_xor_si128(m0,_mm_srli_epi64(m9,59)); \
90+
m0 = _mm_xor_si128(m0,_mm_srli_epi64(m9,57)); \
91+
m0 = _mm_xor_si128(m0,_mm_srli_epi64(m9,55)); \
92+
m0 = _mm_xor_si128(m0,_mm_srli_epi64(m9,52)); \
93+
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* RELIC is an Efficient LIbrary for Cryptography
3+
* Copyright (C) 2007-2011 RELIC Authors
4+
*
5+
* This file is part of RELIC. RELIC is legal property of its developers,
6+
* whose names are not listed here. Please refer to the COPYRIGHT file
7+
* for contact information.
8+
*
9+
* RELIC is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* RELIC is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with RELIC. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
/**
24+
* @file
25+
*
26+
* Implementation of the low-level multiple precision division functions.
27+
*
28+
* @version $Id: relic_bn_div_low.c 677 2011-03-05 22:19:43Z dfaranha $
29+
* @ingroup bn
30+
*/
31+
32+
#include <gmp.h>
33+
34+
#include "relic_bn.h"
35+
#include "relic_bn_low.h"
36+
37+
/*============================================================================*/
38+
/* Public definitions */
39+
/*============================================================================*/
40+
41+
void bn_divn_low(dig_t *c, dig_t *d, dig_t *a, int sa, dig_t *b, int sb) {
42+
mpn_tdiv_qr(c, d, 0, a, sa, b, sb);
43+
}
44+
45+
void bn_div1_low(dig_t *c, dig_t *d, dig_t *a, int size, dig_t b) {
46+
*d = mpn_divrem_1(c, 0, a, size, b);
47+
}
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* RELIC is an Efficient LIbrary for Cryptography
3+
* Copyright (C) 2007-2011 RELIC Authors
4+
*
5+
* This file is part of RELIC. RELIC is legal property of its developers,
6+
* whose names are not listed here. Please refer to the COPYRIGHT file
7+
* for contact information.
8+
*
9+
* RELIC is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* RELIC is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with RELIC. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
/**
24+
* @file
25+
*
26+
* Implementation of the low-level multiple precision integer modular reduction
27+
* functions.
28+
*
29+
* @version $Id: relic_bn_mod_low.c 677 2011-03-05 22:19:43Z dfaranha $
30+
* @ingroup bn
31+
*/
32+
33+
#include <gmp.h>
34+
#include <string.h>
35+
36+
#include "relic_bn.h"
37+
#include "relic_bn_low.h"
38+
#include "relic_util.h"
39+
40+
/*============================================================================*/
41+
/* Public definitions */
42+
/*============================================================================*/
43+
44+
void bn_modn_low(dig_t *c, dig_t *a, int sa, dig_t *m, int sm, dig_t u) {
45+
int i;
46+
dig_t r, carry, *tmpc;
47+
48+
tmpc = c;
49+
50+
for (i = 0; i < sa; i++, tmpc++, a++) {
51+
*tmpc = *a;
52+
}
53+
54+
tmpc = c;
55+
56+
for (i = 0; i < sm; i++, tmpc++) {
57+
r = (dig_t)(*tmpc * u);
58+
carry = mpn_addmul_1(tmpc, m, sm, r);
59+
mpn_add_1(tmpc + sm, tmpc + sm, sm - i + 1, carry);
60+
}
61+
bn_rshd_low(c, c, 2 * sm + 1, sm);
62+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* RELIC is an Efficient LIbrary for Cryptography
3+
* Copyright (C) 2007-2011 RELIC Authors
4+
*
5+
* This file is part of RELIC. RELIC is legal property of its developers,
6+
* whose names are not listed here. Please refer to the COPYRIGHT file
7+
* for contact information.
8+
*
9+
* RELIC is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* RELIC is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with RELIC. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
/**
24+
* @file
25+
*
26+
* Implementation of the multiple precision integer arithmetic multiplication
27+
* functions.
28+
*
29+
* @version $Id: relic_bn_mul_low.c 976 2012-01-07 02:21:45Z dfaranha $
30+
* @ingroup bn
31+
*/
32+
33+
#include <gmp.h>
34+
35+
#include "relic_bn.h"
36+
#include "relic_bn_low.h"
37+
#include "relic_util.h"
38+
39+
/*============================================================================*/
40+
/* Public definitions */
41+
/*============================================================================*/
42+
43+
dig_t bn_muladd_low(dig_t *c, dig_t *a, dig_t digit, int size) {
44+
return mpn_addmul_1(c, a, size, digit);
45+
}
46+
47+
dig_t bn_mul1_low(dig_t *c, dig_t *a, dig_t digit, int size) {
48+
return mpn_mul_1(c, a, size, digit);
49+
}
50+
51+
void bn_muln_low(dig_t *c, dig_t *a, dig_t *b, int size) {
52+
mpn_mul_n(c, a, b, size);
53+
}
54+
55+
void bn_muld_low(dig_t *c, dig_t *a, int sizea, dig_t *b, int sizeb,
56+
int low, int high) {
57+
(void) low;
58+
(void) high;
59+
mpn_mul(c, a, sizea, b, sizeb);
60+
}
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* RELIC is an Efficient LIbrary for Cryptography
3+
* Copyright (C) 2007-2011 RELIC Authors
4+
*
5+
* This file is part of RELIC. RELIC is legal property of its developers,
6+
* whose names are not listed here. Please refer to the COPYRIGHT file
7+
* for contact information.
8+
*
9+
* RELIC is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* RELIC is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with RELIC. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
/**
24+
* @file
25+
*
26+
* Implementation of the multiple precision integer arithmetic multiplication
27+
* functions.
28+
*
29+
* @version $Id: relic_bn_sqr_low.c 677 2011-03-05 22:19:43Z dfaranha $
30+
* @ingroup bn
31+
*/
32+
33+
#include <gmp.h>
34+
35+
#include "relic_bn.h"
36+
#include "relic_bn_low.h"
37+
#include "relic_util.h"
38+
39+
/*============================================================================*/
40+
/* Public definitions */
41+
/*============================================================================*/
42+
43+
void bn_sqradd_low(dig_t *c, dig_t *a, int size) {
44+
dig_t carry;
45+
dig_t digit;
46+
47+
digit = *a;
48+
49+
carry = mpn_addmul_1(c, a, size, digit);
50+
mpn_add_1(c+size, c+size, size, carry);
51+
if (size - 1 > 0) {
52+
carry = mpn_addmul_1(c+1, a+1, size-1, digit);
53+
mpn_add_1(c+size, c+size, size, carry);
54+
}
55+
}
56+
57+
void bn_sqrn_low(dig_t *c, dig_t *a, int size) {
58+
mpn_mul_n(c, a, a, size);
59+
}

0 commit comments

Comments
 (0)