ltc sync
Karel Miko
6 years ago
14 | 14 |
Process an entire GCM packet in one call.
|
15 | 15 |
@param key The secret key
|
16 | 16 |
@param keylen The length of the secret key
|
17 | |
@param iv The initial vector
|
18 | |
@param ivlen The length of the initial vector
|
|
17 |
@param iv The initialization vector
|
|
18 |
@param ivlen The length of the initialization vector
|
19 | 19 |
@param aad The additional authentication data (header)
|
20 | 20 |
@param aadlen The length of the aad
|
21 | 21 |
@param in The plaintext
|
19 | 19 |
@param cipher Index of cipher to use
|
20 | 20 |
@param key The secret key
|
21 | 21 |
@param keylen The length of the secret key
|
22 | |
@param IV The initial vector
|
23 | |
@param IVlen The length of the initial vector
|
|
22 |
@param IV The initialization vector
|
|
23 |
@param IVlen The length of the initialization vector
|
24 | 24 |
@param adata The additional authentication data (header)
|
25 | 25 |
@param adatalen The length of the adata
|
26 | 26 |
@param pt The plaintext
|
87 | 87 |
return CRYPT_NOP;
|
88 | 88 |
#else
|
89 | 89 |
static const struct {
|
90 | |
char *msg;
|
|
90 |
const char *msg;
|
91 | 91 |
unsigned char hash[28];
|
92 | 92 |
} tests[] = {
|
93 | 93 |
{ "abc",
|
89 | 89 |
return CRYPT_NOP;
|
90 | 90 |
#else
|
91 | 91 |
static const struct {
|
92 | |
char *msg;
|
|
92 |
const char *msg;
|
93 | 93 |
unsigned char hash[48];
|
94 | 94 |
} tests[] = {
|
95 | 95 |
{ "abc",
|
89 | 89 |
return CRYPT_NOP;
|
90 | 90 |
#else
|
91 | 91 |
static const struct {
|
92 | |
char *msg;
|
|
92 |
const char *msg;
|
93 | 93 |
unsigned char hash[28];
|
94 | 94 |
} tests[] = {
|
95 | 95 |
{ "abc",
|
89 | 89 |
return CRYPT_NOP;
|
90 | 90 |
#else
|
91 | 91 |
static const struct {
|
92 | |
char *msg;
|
|
92 |
const char *msg;
|
93 | 93 |
unsigned char hash[32];
|
94 | 94 |
} tests[] = {
|
95 | 95 |
{ "abc",
|
74 | 74 |
zeromem((hmac->key) + keylen, (size_t)(LTC_HMAC_BLOCKSIZE - keylen));
|
75 | 75 |
}
|
76 | 76 |
|
77 | |
/* Create the initial vector for step (3) */
|
|
77 |
/* Create the initialization vector for step (3) */
|
78 | 78 |
for(i=0; i < LTC_HMAC_BLOCKSIZE; i++) {
|
79 | 79 |
buf[i] = hmac->key[i] ^ 0x36;
|
80 | 80 |
}
|
13 | 13 |
*/
|
14 | 14 |
|
15 | 15 |
#if (ARGTYPE == 0)
|
16 | |
void crypt_argchk(char *v, char *s, int d)
|
|
16 |
void crypt_argchk(const char *v, const char *s, int d)
|
17 | 17 |
{
|
18 | 18 |
fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n",
|
19 | 19 |
v, d, s);
|
7 | 7 |
*/
|
8 | 8 |
#include "tomcrypt.h"
|
9 | 9 |
|
10 | |
ltc_math_descriptor ltc_mp;
|
|
10 |
/* Initialize ltc_mp to nulls, to force allocation on all platforms, including macOS. */
|
|
11 |
ltc_math_descriptor ltc_mp = { 0 };
|
11 | 12 |
|
12 | 13 |
/* ref: $Format:%D$ */
|
13 | 14 |
/* git commit: $Format:%H$ */
|
19 | 19 |
"CRYPT_ERROR",
|
20 | 20 |
"Non-fatal 'no-operation' requested.",
|
21 | 21 |
|
22 | |
"Invalid keysize for block cipher.",
|
|
22 |
"Invalid key size.",
|
23 | 23 |
"Invalid number of rounds for block cipher.",
|
24 | 24 |
"Algorithm failed test vectors.",
|
25 | 25 |
|
15 | 15 |
#ifdef LTC_CBC_MODE
|
16 | 16 |
|
17 | 17 |
/**
|
18 | |
Get the current initial vector
|
19 | |
@param IV [out] The destination of the initial vector
|
20 | |
@param len [in/out] The max size and resulting size of the initial vector
|
|
18 |
Get the current initialization vector
|
|
19 |
@param IV [out] The destination of the initialization vector
|
|
20 |
@param len [in/out] The max size and resulting size of the initialization vector
|
21 | 21 |
@param cbc The CBC state
|
22 | 22 |
@return CRYPT_OK if successful
|
23 | 23 |
*/
|
16 | 16 |
#ifdef LTC_CBC_MODE
|
17 | 17 |
|
18 | 18 |
/**
|
19 | |
Set an initial vector
|
20 | |
@param IV The initial vector
|
|
19 |
Set an initialization vector
|
|
20 |
@param IV The initialization vector
|
21 | 21 |
@param len The length of the vector (in octets)
|
22 | 22 |
@param cbc The CBC state
|
23 | 23 |
@return CRYPT_OK if successful
|
17 | 17 |
/**
|
18 | 18 |
Initialize a CBC context
|
19 | 19 |
@param cipher The index of the cipher desired
|
20 | |
@param IV The initial vector
|
|
20 |
@param IV The initialization vector
|
21 | 21 |
@param key The secret key
|
22 | 22 |
@param keylen The length of the secret key (octets)
|
23 | 23 |
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
15 | 15 |
#ifdef LTC_CFB_MODE
|
16 | 16 |
|
17 | 17 |
/**
|
18 | |
Get the current initial vector
|
19 | |
@param IV [out] The destination of the initial vector
|
20 | |
@param len [in/out] The max size and resulting size of the initial vector
|
|
18 |
Get the current initialization vector
|
|
19 |
@param IV [out] The destination of the initialization vector
|
|
20 |
@param len [in/out] The max size and resulting size of the initialization vector
|
21 | 21 |
@param cfb The CFB state
|
22 | 22 |
@return CRYPT_OK if successful
|
23 | 23 |
*/
|
15 | 15 |
#ifdef LTC_CFB_MODE
|
16 | 16 |
|
17 | 17 |
/**
|
18 | |
Set an initial vector
|
19 | |
@param IV The initial vector
|
|
18 |
Set an initialization vector
|
|
19 |
@param IV The initialization vector
|
20 | 20 |
@param len The length of the vector (in octets)
|
21 | 21 |
@param cfb The CFB state
|
22 | 22 |
@return CRYPT_OK if successful
|
18 | 18 |
/**
|
19 | 19 |
Initialize a CFB context
|
20 | 20 |
@param cipher The index of the cipher desired
|
21 | |
@param IV The initial vector
|
|
21 |
@param IV The initialization vector
|
22 | 22 |
@param key The secret key
|
23 | 23 |
@param keylen The length of the secret key (octets)
|
24 | 24 |
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
15 | 15 |
#ifdef LTC_CTR_MODE
|
16 | 16 |
|
17 | 17 |
/**
|
18 | |
Get the current initial vector
|
19 | |
@param IV [out] The destination of the initial vector
|
20 | |
@param len [in/out] The max size and resulting size of the initial vector
|
|
18 |
Get the current initialization vector
|
|
19 |
@param IV [out] The destination of the initialization vector
|
|
20 |
@param len [in/out] The max size and resulting size of the initialization vector
|
21 | 21 |
@param ctr The CTR state
|
22 | 22 |
@return CRYPT_OK if successful
|
23 | 23 |
*/
|
15 | 15 |
#ifdef LTC_CTR_MODE
|
16 | 16 |
|
17 | 17 |
/**
|
18 | |
Set an initial vector
|
19 | |
@param IV The initial vector
|
|
18 |
Set an initialization vector
|
|
19 |
@param IV The initialization vector
|
20 | 20 |
@param len The length of the vector (in octets)
|
21 | 21 |
@param ctr The CTR state
|
22 | 22 |
@return CRYPT_OK if successful
|
18 | 18 |
/**
|
19 | 19 |
Initialize a CTR context
|
20 | 20 |
@param cipher The index of the cipher desired
|
21 | |
@param IV The initial vector
|
|
21 |
@param IV The initialization vector
|
22 | 22 |
@param key The secret key
|
23 | 23 |
@param keylen The length of the secret key (octets)
|
24 | 24 |
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
15 | 15 |
#ifdef LTC_OFB_MODE
|
16 | 16 |
|
17 | 17 |
/**
|
18 | |
Get the current initial vector
|
19 | |
@param IV [out] The destination of the initial vector
|
20 | |
@param len [in/out] The max size and resulting size of the initial vector
|
|
18 |
Get the current initialization vector
|
|
19 |
@param IV [out] The destination of the initialization vector
|
|
20 |
@param len [in/out] The max size and resulting size of the initialization vector
|
21 | 21 |
@param ofb The OFB state
|
22 | 22 |
@return CRYPT_OK if successful
|
23 | 23 |
*/
|
15 | 15 |
#ifdef LTC_OFB_MODE
|
16 | 16 |
|
17 | 17 |
/**
|
18 | |
Set an initial vector
|
19 | |
@param IV The initial vector
|
|
18 |
Set an initialization vector
|
|
19 |
@param IV The initialization vector
|
20 | 20 |
@param len The length of the vector (in octets)
|
21 | 21 |
@param ofb The OFB state
|
22 | 22 |
@return CRYPT_OK if successful
|
18 | 18 |
/**
|
19 | 19 |
Initialize a OFB context
|
20 | 20 |
@param cipher The index of the cipher desired
|
21 | |
@param IV The initial vector
|
|
21 |
@param IV The initialization vector
|
22 | 22 |
@param key The secret key
|
23 | 23 |
@param keylen The length of the secret key (octets)
|
24 | 24 |
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
56 | 56 |
unsigned long i, j;
|
57 | 57 |
|
58 | 58 |
if (inlen == 0) return CRYPT_OK; /* nothing to do */
|
59 | |
LTC_ARGCHK(st != NULL);
|
60 | |
LTC_ARGCHK(in != NULL);
|
61 | |
LTC_ARGCHK(out != NULL);
|
|
59 |
|
|
60 |
LTC_ARGCHK(st != NULL);
|
|
61 |
LTC_ARGCHK(in != NULL);
|
|
62 |
LTC_ARGCHK(out != NULL);
|
|
63 |
LTC_ARGCHK(st->ivlen != 0);
|
62 | 64 |
|
63 | 65 |
if (st->ksleft > 0) {
|
64 | 66 |
j = MIN(st->ksleft, inlen);
|
34 | 34 |
LTC_ARGCHK(key != NULL);
|
35 | 35 |
LTC_ARGCHK(keylen == 32 || keylen == 16);
|
36 | 36 |
|
|
37 |
if (rounds == 0) rounds = 20;
|
|
38 |
|
37 | 39 |
LOAD32L(st->input[4], key + 0);
|
38 | 40 |
LOAD32L(st->input[5], key + 4);
|
39 | 41 |
LOAD32L(st->input[6], key + 8);
|