chachapoly_state > chacha20poly1305_state

This commit is contained in:
Karel Miko 2017-03-30 20:29:41 +02:00
parent 11a9dc50b3
commit 3a05f0331d
10 changed files with 18 additions and 18 deletions

View File

@ -18,7 +18,7 @@
@param inlen The length of the ChaCha20Poly1305 data. @param inlen The length of the ChaCha20Poly1305 data.
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int chacha20poly1305_add_aad(chachapoly_state *st, const unsigned char *in, unsigned long inlen) int chacha20poly1305_add_aad(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen)
{ {
int err; int err;

View File

@ -19,7 +19,7 @@
@param out [out] The plaintext (length inlen) @param out [out] The plaintext (length inlen)
@return CRYPT_OK if successful @return CRYPT_OK if successful
*/ */
int chacha20poly1305_decrypt(chachapoly_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out) int chacha20poly1305_decrypt(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out)
{ {
unsigned char padzero[16] = { 0 }; unsigned char padzero[16] = { 0 };
unsigned long padlen; unsigned long padlen;

View File

@ -18,7 +18,7 @@
@param taglen [in/out] The length of the MAC tag @param taglen [in/out] The length of the MAC tag
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int chacha20poly1305_done(chachapoly_state *st, unsigned char *tag, unsigned long *taglen) int chacha20poly1305_done(chacha20poly1305_state *st, unsigned char *tag, unsigned long *taglen)
{ {
unsigned char padzero[16] = { 0 }; unsigned char padzero[16] = { 0 };
unsigned long padlen; unsigned long padlen;

View File

@ -19,7 +19,7 @@
@param out [out] The ciphertext (length inlen) @param out [out] The ciphertext (length inlen)
@return CRYPT_OK if successful @return CRYPT_OK if successful
*/ */
int chacha20poly1305_encrypt(chachapoly_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out) int chacha20poly1305_encrypt(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out)
{ {
unsigned char padzero[16] = { 0 }; unsigned char padzero[16] = { 0 };
unsigned long padlen; unsigned long padlen;

View File

@ -18,7 +18,7 @@
@param keylen The length of the secret key (octets) @param keylen The length of the secret key (octets)
@return CRYPT_OK if successful @return CRYPT_OK if successful
*/ */
int chacha20poly1305_init(chachapoly_state *st, const unsigned char *key, unsigned long keylen) int chacha20poly1305_init(chacha20poly1305_state *st, const unsigned char *key, unsigned long keylen)
{ {
return chacha_setup(&st->chacha, key, keylen, 20); return chacha_setup(&st->chacha, key, keylen, 20);
} }

View File

@ -35,7 +35,7 @@ int chacha20poly1305_memory(const unsigned char *key, unsigned long keylen,
unsigned char *tag, unsigned long *taglen, unsigned char *tag, unsigned long *taglen,
int direction) int direction)
{ {
chachapoly_state st; chacha20poly1305_state st;
int err; int err;
LTC_ARGCHK(key != NULL); LTC_ARGCHK(key != NULL);
@ -62,7 +62,7 @@ int chacha20poly1305_memory(const unsigned char *key, unsigned long keylen,
err = chacha20poly1305_done(&st, tag, taglen); err = chacha20poly1305_done(&st, tag, taglen);
LBL_ERR: LBL_ERR:
#ifdef LTC_CLEAN_STACK #ifdef LTC_CLEAN_STACK
zeromem(&st, sizeof(chachapoly_state)); zeromem(&st, sizeof(chacha20poly1305_state));
#endif #endif
return err; return err;
} }

View File

@ -18,7 +18,7 @@
@param inlen The length of the IV (must be 12 or 8) @param inlen The length of the IV (must be 12 or 8)
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int chacha20poly1305_setiv(chachapoly_state *st, const unsigned char *iv, unsigned long ivlen) int chacha20poly1305_setiv(chacha20poly1305_state *st, const unsigned char *iv, unsigned long ivlen)
{ {
chacha_state tmp_st; chacha_state tmp_st;
int i, err; int i, err;

View File

@ -19,7 +19,7 @@
@param sequence_number 64bit sequence number which is incorporated into IV as described in RFC7905 @param sequence_number 64bit sequence number which is incorporated into IV as described in RFC7905
@return CRYPT_OK on success @return CRYPT_OK on success
*/ */
int chacha20poly1305_setiv_rfc7905(chachapoly_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 sequence_number) int chacha20poly1305_setiv_rfc7905(chacha20poly1305_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 sequence_number)
{ {
int i; int i;
unsigned char combined_iv[12] = { 0 }; unsigned char combined_iv[12] = { 0 };

View File

@ -16,7 +16,7 @@ int chacha20poly1305_test(void)
#ifndef LTC_TEST #ifndef LTC_TEST
return CRYPT_NOP; return CRYPT_NOP;
#else #else
chachapoly_state st1, st2; chacha20poly1305_state st1, st2;
unsigned char k[] = { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }; unsigned char k[] = { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f };
unsigned char iv[] = { 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 }; unsigned char iv[] = { 0x07, 0x00, 0x00, 0x00, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 };
unsigned char aad[] = { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 }; unsigned char aad[] = { 0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 };

View File

@ -505,18 +505,18 @@ typedef struct {
ulong64 aadlen; ulong64 aadlen;
ulong64 ctlen; ulong64 ctlen;
int aadflg; int aadflg;
} chachapoly_state; } chacha20poly1305_state;
#define CHCHA20POLY1305_ENCRYPT 0 #define CHCHA20POLY1305_ENCRYPT 0
#define CHCHA20POLY1305_DECRYPT 1 #define CHCHA20POLY1305_DECRYPT 1
int chacha20poly1305_init(chachapoly_state *st, const unsigned char *key, unsigned long keylen); int chacha20poly1305_init(chacha20poly1305_state *st, const unsigned char *key, unsigned long keylen);
int chacha20poly1305_setiv(chachapoly_state *st, const unsigned char *iv, unsigned long ivlen); int chacha20poly1305_setiv(chacha20poly1305_state *st, const unsigned char *iv, unsigned long ivlen);
int chacha20poly1305_setiv_rfc7905(chachapoly_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 sequence_number); int chacha20poly1305_setiv_rfc7905(chacha20poly1305_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 sequence_number);
int chacha20poly1305_add_aad(chachapoly_state *st, const unsigned char *in, unsigned long inlen); int chacha20poly1305_add_aad(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen);
int chacha20poly1305_encrypt(chachapoly_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); int chacha20poly1305_encrypt(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);
int chacha20poly1305_decrypt(chachapoly_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); int chacha20poly1305_decrypt(chacha20poly1305_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out);
int chacha20poly1305_done(chachapoly_state *st, unsigned char *tag, unsigned long *taglen); int chacha20poly1305_done(chacha20poly1305_state *st, unsigned char *tag, unsigned long *taglen);
int chacha20poly1305_memory(const unsigned char *key, unsigned long keylen, int chacha20poly1305_memory(const unsigned char *key, unsigned long keylen,
const unsigned char *iv, unsigned long ivlen, const unsigned char *iv, unsigned long ivlen,
const unsigned char *aad, unsigned long aadlen, const unsigned char *aad, unsigned long aadlen,