• 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_OPTIMIZER_H
17 #define BN_OPTIMIZER_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_CRYPTO_BN
21 
22 #include "bn_basic.h"
23 
24 #ifdef __cplusplus
25 extern "c" {
26 #endif
27 
28 #define CRYPT_OPTIMIZER_MAXDEEP 10
29 
30 /*
31  * Peak memory usage of the bn process during RSA key generation. BN_NUM stands for HITLS_CRYPT_OPTIMIZER_BN_NUM.
32  * |----------------------------+--------+--------+--------+--------+--------|
33  * | key bits\memory(Kb)\BN_NUM |   16   |   24   |   32   |   48   |   64   |
34  * |----------------------------+--------+--------+--------+--------+--------|
35  * |           rsa1024          |  9.0   |  9.7   |  9.7   |  10.8  |  12.0  |
36  * |           rsa2048          |  20.4  |  21.0  |  21.1  |  22.6  |  22.6  |
37  * |           rsa3072          |  37.8  |  38.3  |  38.5  |  40.0  |  40.0  |
38  * |           rsa4096          |  73.5  |  73.5  |  74.2  |  75.7  |  75.7  |
39  * |----------------------------+--------+--------+--------+--------+--------|
40  *
41  * The number of chunk during RSA key generation. BN_NUM stands for HITLS_CRYPT_OPTIMIZER_BN_NUM.
42  * |----------------------------+--------+--------+--------+--------+--------|
43  * |key bits\chunk number\BN_NUM|   16   |   24   |   32   |   48   |   64   |
44  * |----------------------------+--------+--------+--------+--------+--------|
45  * |           rsa1024          |  352   |  352   |  193   |  193   |  193   |
46  * |           rsa2048          |  1325  |  1035  |  745   |  745   |  455   |
47  * |           rsa3072          |  1597  |  1227  |  857   |  857   |  487   |
48  * |           rsa4096          |  2522  |  1967  |  1412  |  1412  |  857   |
49  * |----------------------------+--------+--------+--------+--------+--------|
50  */
51 #ifndef HITLS_CRYPT_OPTIMIZER_BN_NUM
52     #define HITLS_CRYPT_OPTIMIZER_BN_NUM 32
53 #endif
54 
55 typedef struct ChunkStruct {
56     uint32_t occupied;       /** < occupied of current chunk */
57     BN_BigNum bigNums[HITLS_CRYPT_OPTIMIZER_BN_NUM];       /** < preset BN_BigNums */
58     struct ChunkStruct *prev;  /** < prev optimizer node */
59     struct ChunkStruct *next;  /** < prev optimizer node */
60 } Chunk;
61 
62 struct BnOptimizer {
63     uint32_t deep;      /* depth of stack */
64     uint32_t used[CRYPT_OPTIMIZER_MAXDEEP];   /* size of the used stack */
65     Chunk *curChunk;         /** < chunk, the last point*/
66     void *libCtx;
67 };
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 #endif /* HITLS_CRYPTO_BN */
74 
75 #endif
76