00001
00018 #ifndef C4E_RSA_H
00019 #define C4E_RSA_H
00020
00021
00022
00023
00024 #include "c4e_dlc.h"
00025 #include "c4e_algo32.h"
00026 #include "c4e_hash.h"
00027
00028
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032
00033
00042
00043
00044
00070 typedef struct
00071 {
00072 C4eElement dp;
00073 C4eElement dq;
00088 C4eElemTriple p;
00089
00105 C4eElemTriple q;
00106
00107 } C4eRsaKeyPrv;
00108
00109
00110
00111
00112
00113
00133 #define C4E_RSA_TMPID_KEY_CHECK (1U)
00134
00138 #define C4E_RSA_TMPID_PKCS1V1_ENCRYPT (3U)
00139
00143 #define C4E_RSA_TMPID_PKCS1V1_DECRYPT (5U)
00144
00148 #define C4E_RSA_TMPID_PKCS1V1_SIGN (5U)
00149
00153 #define C4E_RSA_TMPID_PKCS1V1_VERIFY (3U)
00154
00158 #define C4E_RSA_TMPID_PKCS1V2_ENCRYPT (3U)
00159
00163 #define C4E_RSA_TMPID_PKCS1V2_DECRYPT (5U)
00164
00168 #define C4E_RSA_TMPID_PKCS1V2_SIGN (5U)
00169
00179 #define C4E_RSA_TMPID_PKCS1V2_VERIFY (4U)
00180
00181
00199 #define C4E_RSA_TMPID_PKCS1_MAX (4U)
00200
00201
00211 #define C4E_RSA_TMPID_PKCS1_WORSTCASE (5U)
00212
00213
00220
00221
00222
00223
00254 #define C4E_RSA_TMP_NUM(tmpid, keylen) \
00255 ((tmpid) * C4E_ALGO32_DIGITS_NUM( \
00256 C4E_MODN_POW_SPACE( \
00257 C4E_ELEM_DIGITS_NUM(keylen)) * C4E_ARCH_DIGIT_SIZE))
00258
00259
00260
00261
00273 #define C4E_RSA_PKCS1V1_EBOH (11U)
00274
00275
00276
00277
00293 #define C4E_RSA_OAEP_EMOH(hlen) (((hlen) * 2U) + 2U)
00294
00295
00296
00297
00331 #define C4E_RSA_PSS_EMLEN(hlen, slen) ((hlen) + (slen) + 2U)
00332
00333
00334
00335
00336
00337
00338
00339
00340
00400 C4eSysStatus c4e_rsa_encrypt_pkcs1v1(C4eDlcDomain* C4E_RESTRICT dom,
00401 C4E_CONST C4eElement* C4E_RESTRICT e,
00402 C4E_CONST C4eArchUint8* C4E_RESTRICT plain,
00403 C4eArchSize len,
00404 C4eAlgo32Digit tmp[C4E_RESTRICT],
00405 C4eArchUint8* C4E_RESTRICT cipher);
00406
00407
00408
00482 C4eSysStatus c4e_rsa_decrypt_pkcs1v1(C4E_CONST C4eDlcDomain* C4E_RESTRICT dom,
00483 C4eRsaKeyPrv* key,
00484 C4E_CONST C4eArchUint8* C4E_RESTRICT cipher,
00485 C4eAlgo32Digit tmp[C4E_RESTRICT],
00486 C4eArchUint8* C4E_RESTRICT plain,
00487 C4eArchSize* C4E_RESTRICT plen);
00488
00489
00490
00571 C4eSysStatus c4e_rsa_sign_pkcs1v1(C4E_CONST C4eDlcDomain* C4E_RESTRICT dom,
00572 C4eRsaKeyPrv* key,
00573 C4eHashId hid,
00574 C4E_CONST C4eArchUint8* C4E_RESTRICT digest,
00575 C4eAlgo32Digit tmp[C4E_RESTRICT],
00576 C4eArchUint8* C4E_RESTRICT signature);
00577
00578
00579
00647 C4eSysStatus c4e_rsa_verify_pkcs1v1(C4eDlcDomain* C4E_RESTRICT dom,
00648 C4E_CONST C4eElement* C4E_RESTRICT e,
00649 C4eHashId hid,
00650 C4E_CONST C4eArchUint8* C4E_RESTRICT digest,
00651 C4eAlgo32Digit tmp[C4E_RESTRICT],
00652 C4eArchUint8* C4E_RESTRICT signature,
00653 C4eArchSize len);
00654
00655
00656
00733 C4eSysStatus c4e_rsa_encrypt_pkcs1v2(C4eDlcDomain* C4E_RESTRICT dom,
00734 C4E_CONST C4eElement* C4E_RESTRICT e,
00735 C4eHashId hid,
00736 C4E_CONST C4eArchUint8* C4E_RESTRICT plain,
00737 C4eArchSize len,
00738 C4eAlgo32Digit tmp[C4E_RESTRICT],
00739 C4eArchUint8* C4E_RESTRICT cipher);
00740
00741
00742
00815 C4eSysStatus c4e_rsa_decrypt_pkcs1v2(C4E_CONST C4eDlcDomain* C4E_RESTRICT dom,
00816 C4eRsaKeyPrv* key,
00817 C4eHashId hid,
00818 C4E_CONST C4eArchUint8* C4E_RESTRICT cipher,
00819 C4eAlgo32Digit tmp[C4E_RESTRICT],
00820 C4eArchUint8* C4E_RESTRICT plain,
00821 C4eArchSize* C4E_RESTRICT plen);
00822
00823
00824
00924 C4eSysStatus c4e_rsa_sign_pkcs1v2(C4E_CONST C4eDlcDomain* C4E_RESTRICT dom,
00925 C4eRsaKeyPrv* key,
00926 C4eArchSize slen,
00927 C4eHashId hid,
00928 C4E_CONST C4eArchUint8* C4E_RESTRICT digest,
00929 C4eAlgo32Digit tmp[C4E_RESTRICT],
00930 C4eArchUint8* C4E_RESTRICT signature);
00931
00932
00933
00934
01009 C4eSysStatus c4e_rsa_verify_pkcs1v2(C4eDlcDomain* C4E_RESTRICT dom,
01010 C4E_CONST C4eElement* C4E_RESTRICT e,
01011 C4eHashId hid,
01012 C4eArchUint8* C4E_RESTRICT digest,
01013 C4eArchUint8* C4E_RESTRICT signature,
01014 C4eArchSize len,
01015 C4eAlgo32Digit tmp[C4E_RESTRICT]);
01016
01017
01018
01054 C4eSysStatus c4e_rsa_keychk_prv(C4E_CONST C4eDlcDomain* C4E_RESTRICT dom,
01055 C4E_CONST C4eRsaKeyPrv* C4E_RESTRICT key,
01056 C4eAlgo32Digit tmp[C4E_RESTRICT]);
01057
01058
01059
01090 C4eSysStatus c4e_rsa_keychk_pub(C4E_CONST C4eDlcDomain* C4E_RESTRICT dom,
01091 C4E_CONST C4eElement* C4E_RESTRICT e,
01092 C4eAlgo32Digit tmp[C4E_RESTRICT]);
01093
01094
01099 #ifdef __cplusplus
01100 }
01101 #endif
01102
01103
01104 #endif
01105
01106
01107
01108
01109