/src/relic/src/fb/relic_fb_itr.c
Line | Count | Source |
1 | | /* |
2 | | * RELIC is an Efficient LIbrary for Cryptography |
3 | | * Copyright (c) 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 modify it under the |
10 | | * terms of the version 2.1 (or later) of the GNU Lesser General Public License |
11 | | * as published by the Free Software Foundation; or version 2.0 of the Apache |
12 | | * License as published by the Apache Software Foundation. See the LICENSE files |
13 | | * for more details. |
14 | | * |
15 | | * RELIC is distributed in the hope that it will be useful, but WITHOUT ANY |
16 | | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
17 | | * A PARTICULAR PURPOSE. See the LICENSE files for more details. |
18 | | * |
19 | | * You should have received a copy of the GNU Lesser General Public or the |
20 | | * Apache License along with RELIC. If not, see <https://www.gnu.org/licenses/> |
21 | | * or <https://www.apache.org/licenses/>. |
22 | | */ |
23 | | |
24 | | /** |
25 | | * @file |
26 | | * |
27 | | * Implementation of the iterated squaring/square-root of a binary field |
28 | | * element. |
29 | | * |
30 | | * @ingroup fb |
31 | | */ |
32 | | |
33 | | #include <string.h> |
34 | | |
35 | | #include "relic_core.h" |
36 | | #include "relic_conf.h" |
37 | | #include "relic_fb.h" |
38 | | #include "relic_fb_low.h" |
39 | | #include "relic_bn_low.h" |
40 | | #include "relic_util.h" |
41 | | |
42 | | /*============================================================================*/ |
43 | | /* Public definitions */ |
44 | | /*============================================================================*/ |
45 | | |
46 | 0 | void fb_itr_basic(fb_t c, const fb_t a, int b) { |
47 | 0 | fb_copy(c, a); |
48 | 0 | if (b >= 0) { |
49 | 0 | for (int i = 0; i < b; i++) { |
50 | 0 | fb_sqr(c, c); |
51 | 0 | } |
52 | 0 | } else { |
53 | 0 | for (int i = 0; i < -b; i++) { |
54 | 0 | fb_srt(c, c); |
55 | 0 | } |
56 | 0 | } |
57 | 0 | } |
58 | | |
59 | 0 | void fb_itr_pre_quick(fb_st *t, int b) { |
60 | 0 | int i, j, k; |
61 | 0 | fb_t r; |
62 | |
|
63 | 0 | fb_null(r); |
64 | |
|
65 | 0 | RLC_TRY { |
66 | 0 | fb_new(r); |
67 | |
|
68 | 0 | for (i = 0; i < RLC_FB_DIGS * RLC_DIG; i += 4) { |
69 | 0 | for (j = 0; j < 16; j++) { |
70 | 0 | fb_zero(r); |
71 | 0 | fb_set_dig(r, j); |
72 | 0 | fb_lsh(r, r, i); |
73 | 0 | if (b >= 0) { |
74 | 0 | for (k = 0; k < b; k++) { |
75 | 0 | fb_sqr(r, r); |
76 | 0 | } |
77 | 0 | } else { |
78 | 0 | for (k = 0; k < -b; k++) { |
79 | 0 | fb_srt(r, r); |
80 | 0 | } |
81 | 0 | } |
82 | |
|
83 | 0 | fb_copy((dig_t *)t + (4 * i + j) * RLC_FB_DIGS, r); |
84 | 0 | } |
85 | 0 | } |
86 | 0 | } RLC_CATCH_ANY { |
87 | 0 | RLC_THROW(ERR_CAUGHT); |
88 | 0 | } RLC_FINALLY { |
89 | 0 | fb_free(r); |
90 | 0 | } |
91 | 0 | } |
92 | | |
93 | 0 | void fb_itr_quick(fb_t c, const fb_t a, const fb_st *t) { |
94 | 0 | fb_itrn_low(c, a, (dig_t *)t); |
95 | 0 | } |