forked from cryptape/libecc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fp_montgomery.c
60 lines (50 loc) · 1.25 KB
/
fp_montgomery.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright (C) 2017 - This file is part of libecc project
*
* Authors:
* Ryad BENADJILA <[email protected]>
* Arnaud EBALARD <[email protected]>
* Jean-Pierre FLORI <[email protected]>
*
* Contributors:
* Nicolas VIVET <[email protected]>
* Karim KHALFALLAH <[email protected]>
*
* This software is licensed under a dual BSD and GPL v2 license.
* See LICENSE file at the root folder of the project.
*/
#include "fp.h"
#include "fp_add.h"
#include "fp_mul.h"
#include "fp_mul_redc1.h"
#include "fp_montgomery.h"
void fp_add_monty(fp_t out, fp_src_t in1, fp_src_t in2)
{
fp_add(out, in1, in2);
}
void fp_sub_monty(fp_t out, fp_src_t in1, fp_src_t in2)
{
fp_sub(out, in1, in2);
}
void fp_mul_monty(fp_t out, fp_src_t in1, fp_src_t in2)
{
fp_mul_redc1(out, in1, in2);
}
void fp_sqr_monty(fp_t out, fp_src_t in)
{
fp_sqr_redc1(out, in);
}
void fp_div_monty(fp_t out, fp_src_t in1, fp_src_t in2)
{
fp tmp;
fp_check_initialized(in1);
fp_check_initialized(in2);
fp_check_initialized(out);
fp_init(&tmp, out->ctx);
MUST_HAVE(out->ctx == in1->ctx);
MUST_HAVE(out->ctx == in2->ctx);
MUST_HAVE(!fp_iszero(in2));
fp_div(&tmp, in1, in2);
fp_redcify(out, &tmp);
fp_uninit(&tmp);
}