poly_state > poly1305_state
This commit is contained in:
parent
39028bbeed
commit
11a9dc50b3
@ -104,11 +104,11 @@ typedef struct {
|
|||||||
unsigned long leftover;
|
unsigned long leftover;
|
||||||
unsigned char buffer[16];
|
unsigned char buffer[16];
|
||||||
int final;
|
int final;
|
||||||
} poly_state;
|
} poly1305_state;
|
||||||
|
|
||||||
int poly1305_init(poly_state *st, const unsigned char *key, unsigned long keylen);
|
int poly1305_init(poly1305_state *st, const unsigned char *key, unsigned long keylen);
|
||||||
int poly1305_process(poly_state *st, const unsigned char *in, unsigned long inlen);
|
int poly1305_process(poly1305_state *st, const unsigned char *in, unsigned long inlen);
|
||||||
int poly1305_done(poly_state *st, unsigned char *mac, unsigned long *maclen);
|
int poly1305_done(poly1305_state *st, unsigned char *mac, unsigned long *maclen);
|
||||||
int poly1305_test(void);
|
int poly1305_test(void);
|
||||||
int poly1305_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen);
|
int poly1305_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen);
|
||||||
int poly1305_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in, unsigned long inlen, ...);
|
int poly1305_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in, unsigned long inlen, ...);
|
||||||
@ -500,7 +500,7 @@ int f9_test(void);
|
|||||||
#ifdef LTC_CHACHA20POLY1305_MODE
|
#ifdef LTC_CHACHA20POLY1305_MODE
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
poly_state poly;
|
poly1305_state poly;
|
||||||
chacha_state chacha;
|
chacha_state chacha;
|
||||||
ulong64 aadlen;
|
ulong64 aadlen;
|
||||||
ulong64 ctlen;
|
ulong64 ctlen;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#ifdef LTC_POLY1305
|
#ifdef LTC_POLY1305
|
||||||
|
|
||||||
/* internal only */
|
/* internal only */
|
||||||
static void _poly1305_block(poly_state *st, const unsigned char *in, unsigned long inlen)
|
static void _poly1305_block(poly1305_state *st, const unsigned char *in, unsigned long inlen)
|
||||||
{
|
{
|
||||||
const unsigned long hibit = (st->final) ? 0 : (1UL << 24); /* 1 << 128 */
|
const unsigned long hibit = (st->final) ? 0 : (1UL << 24); /* 1 << 128 */
|
||||||
ulong32 r0,r1,r2,r3,r4;
|
ulong32 r0,r1,r2,r3,r4;
|
||||||
@ -86,7 +86,7 @@ static void _poly1305_block(poly_state *st, const unsigned char *in, unsigned lo
|
|||||||
@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 poly1305_init(poly_state *st, const unsigned char *key, unsigned long keylen)
|
int poly1305_init(poly1305_state *st, const unsigned char *key, unsigned long keylen)
|
||||||
{
|
{
|
||||||
LTC_ARGCHK(st != NULL);
|
LTC_ARGCHK(st != NULL);
|
||||||
LTC_ARGCHK(key != NULL);
|
LTC_ARGCHK(key != NULL);
|
||||||
@ -124,7 +124,7 @@ int poly1305_init(poly_state *st, const unsigned char *key, unsigned long keylen
|
|||||||
@param inlen The length of the data to HMAC (octets)
|
@param inlen The length of the data to HMAC (octets)
|
||||||
@return CRYPT_OK if successful
|
@return CRYPT_OK if successful
|
||||||
*/
|
*/
|
||||||
int poly1305_process(poly_state *st, const unsigned char *in, unsigned long inlen)
|
int poly1305_process(poly1305_state *st, const unsigned char *in, unsigned long inlen)
|
||||||
{
|
{
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ int poly1305_process(poly_state *st, const unsigned char *in, unsigned long inle
|
|||||||
@param outlen [in/out] The max size and resulting size of the POLY1305 authentication tag
|
@param outlen [in/out] The max size and resulting size of the POLY1305 authentication tag
|
||||||
@return CRYPT_OK if successful
|
@return CRYPT_OK if successful
|
||||||
*/
|
*/
|
||||||
int poly1305_done(poly_state *st, unsigned char *mac, unsigned long *maclen)
|
int poly1305_done(poly1305_state *st, unsigned char *mac, unsigned long *maclen)
|
||||||
{
|
{
|
||||||
ulong32 h0,h1,h2,h3,h4,c;
|
ulong32 h0,h1,h2,h3,h4,c;
|
||||||
ulong32 g0,g1,g2,g3,g4;
|
ulong32 g0,g1,g2,g3,g4;
|
||||||
|
@ -30,7 +30,7 @@ int poly1305_file(const char *fname, const unsigned char *key, unsigned long key
|
|||||||
#ifdef LTC_NO_FILE
|
#ifdef LTC_NO_FILE
|
||||||
return CRYPT_NOP;
|
return CRYPT_NOP;
|
||||||
#else
|
#else
|
||||||
poly_state st;
|
poly1305_state st;
|
||||||
FILE *in;
|
FILE *in;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
size_t x;
|
size_t x;
|
||||||
@ -60,7 +60,7 @@ int poly1305_file(const char *fname, const unsigned char *key, unsigned long key
|
|||||||
|
|
||||||
LBL_ERR:
|
LBL_ERR:
|
||||||
#ifdef LTC_CLEAN_STACK
|
#ifdef LTC_CLEAN_STACK
|
||||||
zeromem(&st, sizeof(poly_state));
|
zeromem(&st, sizeof(poly1305_state));
|
||||||
#endif
|
#endif
|
||||||
XFREE(buf);
|
XFREE(buf);
|
||||||
return err;
|
return err;
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
int poly1305_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen)
|
int poly1305_memory(const unsigned char *key, unsigned long keylen, const unsigned char *in, unsigned long inlen, unsigned char *mac, unsigned long *maclen)
|
||||||
{
|
{
|
||||||
poly_state st;
|
poly1305_state st;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
LTC_ARGCHK(key != NULL);
|
LTC_ARGCHK(key != NULL);
|
||||||
@ -41,7 +41,7 @@ int poly1305_memory(const unsigned char *key, unsigned long keylen, const unsign
|
|||||||
err = poly1305_done(&st, mac, maclen);
|
err = poly1305_done(&st, mac, maclen);
|
||||||
LBL_ERR:
|
LBL_ERR:
|
||||||
#ifdef LTC_CLEAN_STACK
|
#ifdef LTC_CLEAN_STACK
|
||||||
zeromem(&st, sizeof(poly_state));
|
zeromem(&st, sizeof(poly1305_state));
|
||||||
#endif
|
#endif
|
||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
int poly1305_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in, unsigned long inlen, ...)
|
int poly1305_memory_multi(const unsigned char *key, unsigned long keylen, unsigned char *mac, unsigned long *maclen, const unsigned char *in, unsigned long inlen, ...)
|
||||||
{
|
{
|
||||||
poly_state st;
|
poly1305_state st;
|
||||||
int err;
|
int err;
|
||||||
va_list args;
|
va_list args;
|
||||||
const unsigned char *curptr;
|
const unsigned char *curptr;
|
||||||
@ -54,7 +54,7 @@ int poly1305_memory_multi(const unsigned char *key, unsigned long keylen, unsign
|
|||||||
err = poly1305_done(&st, mac, maclen);
|
err = poly1305_done(&st, mac, maclen);
|
||||||
LBL_ERR:
|
LBL_ERR:
|
||||||
#ifdef LTC_CLEAN_STACK
|
#ifdef LTC_CLEAN_STACK
|
||||||
zeromem(&st, sizeof(poly_state));
|
zeromem(&st, sizeof(poly1305_state));
|
||||||
#endif
|
#endif
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return err;
|
return err;
|
||||||
|
@ -27,7 +27,7 @@ int poly1305_test(void)
|
|||||||
char m[] = "Cryptographic Forum Research Group";
|
char m[] = "Cryptographic Forum Research Group";
|
||||||
unsigned long len = 16, mlen = strlen(m);
|
unsigned long len = 16, mlen = strlen(m);
|
||||||
unsigned char out[1000];
|
unsigned char out[1000];
|
||||||
poly_state st;
|
poly1305_state st;
|
||||||
/* process piece by piece */
|
/* process piece by piece */
|
||||||
poly1305_init(&st, k, 32);
|
poly1305_init(&st, k, 32);
|
||||||
poly1305_process(&st, (unsigned char*)m, 5);
|
poly1305_process(&st, (unsigned char*)m, 5);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user