• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef BN_BASIC_H
17 #define BN_BASIC_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_CRYPTO_BN
21 
22 #include "crypt_bn.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 struct BnMont {
29     uint32_t mSize;   /* *< size of mod in BN_UINT */
30     BN_UINT k0;         /* *< low word of (1/(r - mod[0])) mod r */
31     BN_UINT *mod;       /* *< mod */
32     BN_UINT *one;       /* *< store one */
33     BN_UINT *montRR;    /* *< mont_enc(1) */
34     BN_UINT *b;         /* *< tmpb(1) */
35     BN_UINT *t;         /* *< tmpt(1) ^ 2 */
36 };
37 
38 struct BnCbCtx {
39     void *arg; // callback parameter
40     BN_CallBack cb; // callback function, which is defined by the user
41 };
42 
43 /* Find a pointer address aligned by 'alignment' bytes in the [ptr, ptr + alignment - 1] range.
44    The input parameter alignment cannot be 0. */
AlignedPointer(const void * ptr,uintptr_t alignment)45 static inline BN_UINT *AlignedPointer(const void *ptr, uintptr_t alignment)
46 {
47     uint8_t *p = (uint8_t *)(uintptr_t)ptr + alignment - 1;
48     return (BN_UINT *)((uintptr_t)p - (uintptr_t)p % alignment);
49 }
50 
51 int32_t BnExtend(BN_BigNum *a, uint32_t words);
52 
53 #ifdef __cplusplus
54 }
55 #endif
56 
57 #endif /* HITLS_CRYPTO_BN */
58 
59 #endif