declaration locations for ARM

This commit is contained in:
JacobBarthelmeh
2014-07-24 18:59:39 -06:00
parent c20fdb037e
commit 3f2ee0801a
5 changed files with 62 additions and 43 deletions

View File

@@ -22,13 +22,13 @@
* and Daniel J. Bernstein * and Daniel J. Bernstein
*/ */
#ifdef HAVE_POLY1305
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
#include <cyassl/ctaocrypt/settings.h> #include <cyassl/ctaocrypt/settings.h>
#ifdef HAVE_POLY1305
#include <cyassl/ctaocrypt/poly1305.h> #include <cyassl/ctaocrypt/poly1305.h>
#include <cyassl/ctaocrypt/error-crypt.h> #include <cyassl/ctaocrypt/error-crypt.h>
#include <cyassl/ctaocrypt/logging.h> #include <cyassl/ctaocrypt/logging.h>
@@ -129,6 +129,7 @@
static void poly1305_blocks(Poly1305* ctx, const unsigned char *m, static void poly1305_blocks(Poly1305* ctx, const unsigned char *m,
size_t bytes) { size_t bytes) {
#ifdef POLY130564 #ifdef POLY130564
const word64 hibit = (ctx->final) ? 0 : ((word64)1 << 40); /* 1 << 128 */ const word64 hibit = (ctx->final) ? 0 : ((word64)1 << 40); /* 1 << 128 */
@@ -138,6 +139,19 @@ static void poly1305_blocks(Poly1305* ctx, const unsigned char *m,
word64 c; word64 c;
word128 d0,d1,d2,d; word128 d0,d1,d2,d;
#else
const word32 hibit = (ctx->final) ? 0 : (1 << 24); /* 1 << 128 */
word32 r0,r1,r2,r3,r4;
word32 s1,s2,s3,s4;
word32 h0,h1,h2,h3,h4;
word64 d0,d1,d2,d3,d4;
word32 c;
#endif
#ifdef POLY130564
r0 = ctx->r[0]; r0 = ctx->r[0];
r1 = ctx->r[1]; r1 = ctx->r[1];
r2 = ctx->r[2]; r2 = ctx->r[2];
@@ -182,13 +196,6 @@ static void poly1305_blocks(Poly1305* ctx, const unsigned char *m,
#else /* if not 64 bit then use 32 bit */ #else /* if not 64 bit then use 32 bit */
const word32 hibit = (ctx->final) ? 0 : (1 << 24); /* 1 << 128 */
word32 r0,r1,r2,r3,r4;
word32 s1,s2,s3,s4;
word32 h0,h1,h2,h3,h4;
word64 d0,d1,d2,d3,d4;
word32 c;
r0 = ctx->r[0]; r0 = ctx->r[0];
r1 = ctx->r[1]; r1 = ctx->r[1];
r2 = ctx->r[2]; r2 = ctx->r[2];
@@ -251,8 +258,9 @@ static void poly1305_blocks(Poly1305* ctx, const unsigned char *m,
int Poly1305SetKey(Poly1305* ctx, const byte* key, word32 keySz) { int Poly1305SetKey(Poly1305* ctx, const byte* key, word32 keySz) {
if (keySz != 32 || ctx == NULL) #if defined(POLY130564)
return BAD_FUNC_ARG; word64 t0,t1;
#endif
#ifdef CHACHA_AEAD_TEST #ifdef CHACHA_AEAD_TEST
word32 k; word32 k;
@@ -265,9 +273,10 @@ int Poly1305SetKey(Poly1305* ctx, const byte* key, word32 keySz) {
printf("\n"); printf("\n");
#endif #endif
#if defined(POLY130564) if (keySz != 32 || ctx == NULL)
return BAD_FUNC_ARG;
word64 t0,t1; #if defined(POLY130564)
/* r &= 0xffffffc0ffffffc0ffffffc0fffffff */ /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
t0 = U8TO64(key + 0); t0 = U8TO64(key + 0);
@@ -319,15 +328,26 @@ int Poly1305SetKey(Poly1305* ctx, const byte* key, word32 keySz) {
int Poly1305Final(Poly1305* ctx, byte* mac) { int Poly1305Final(Poly1305* ctx, byte* mac) {
if (ctx == NULL)
return BAD_FUNC_ARG;
#if defined(POLY130564) #if defined(POLY130564)
word64 h0,h1,h2,c; word64 h0,h1,h2,c;
word64 g0,g1,g2; word64 g0,g1,g2;
word64 t0,t1; word64 t0,t1;
#else
word32 h0,h1,h2,h3,h4,c;
word32 g0,g1,g2,g3,g4;
word64 f;
word32 mask;
#endif
if (ctx == NULL)
return BAD_FUNC_ARG;
#if defined(POLY130564)
/* process the remaining block */ /* process the remaining block */
if (ctx->leftover) { if (ctx->leftover) {
size_t i = ctx->leftover; size_t i = ctx->leftover;
@@ -396,11 +416,6 @@ int Poly1305Final(Poly1305* ctx, byte* mac) {
#else /* if not 64 bit then use 32 bit */ #else /* if not 64 bit then use 32 bit */
word32 h0,h1,h2,h3,h4,c;
word32 g0,g1,g2,g3,g4;
word64 f;
word32 mask;
/* process the remaining block */ /* process the remaining block */
if (ctx->leftover) { if (ctx->leftover) {
size_t i = ctx->leftover; size_t i = ctx->leftover;
@@ -487,8 +502,7 @@ int Poly1305Final(Poly1305* ctx, byte* mac) {
int Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes) { int Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes) {
if (ctx == NULL) size_t i;
return BAD_FUNC_ARG;
#ifdef CHACHA_AEAD_TEST #ifdef CHACHA_AEAD_TEST
word32 k; word32 k;
@@ -500,7 +514,9 @@ int Poly1305Update(Poly1305* ctx, const byte* m, word32 bytes) {
} }
printf("\n"); printf("\n");
#endif #endif
size_t i;
if (ctx == NULL)
return BAD_FUNC_ARG;
/* handle leftover */ /* handle leftover */
if (ctx->leftover) { if (ctx->leftover) {

View File

@@ -1837,6 +1837,8 @@ int rabbit_test(void)
#ifdef HAVE_CHACHA #ifdef HAVE_CHACHA
int chacha_test(void) int chacha_test(void)
{ {
ChaCha enc;
ChaCha dec;
byte cipher[32]; byte cipher[32];
byte plain[32]; byte plain[32];
byte input[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; byte input[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
@@ -1844,7 +1846,7 @@ int chacha_test(void)
int i; int i;
int times = 4; int times = 4;
const byte key1[] = static const byte key1[] =
{ {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -1852,7 +1854,7 @@ int chacha_test(void)
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
}; };
const byte key2[] = static const byte key2[] =
{ {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -1860,7 +1862,7 @@ int chacha_test(void)
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
}; };
const byte key3[] = static const byte key3[] =
{ {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
@@ -1869,7 +1871,7 @@ int chacha_test(void)
}; };
/* 128 bit key */ /* 128 bit key */
const byte key4[] = static const byte key4[] =
{ {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
@@ -1878,10 +1880,10 @@ int chacha_test(void)
const byte* keys[] = {key1, key2, key3, key4}; const byte* keys[] = {key1, key2, key3, key4};
const byte ivs1[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; static const byte ivs1[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const byte ivs2[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; static const byte ivs2[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const byte ivs3[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01}; static const byte ivs3[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01};
const byte ivs4[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; static const byte ivs4[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const byte* ivs[] = {ivs1, ivs2, ivs3, ivs4}; const byte* ivs[] = {ivs1, ivs2, ivs3, ivs4};
@@ -1906,8 +1908,6 @@ int chacha_test(void)
else { else {
keySz = 16; keySz = 16;
} }
ChaCha enc;
ChaCha dec;
XMEMCPY(plain, keys[i], keySz); XMEMCPY(plain, keys[i], keySz);
XMEMSET(cipher, 0, 32); XMEMSET(cipher, 0, 32);

View File

@@ -19,8 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#ifndef CHACHA_H #ifndef CTAO_CRYPT_CHACHA_H
#define CHACHA_H #define CTAO_CRYPT_CHACHA_H
#include "types.h" #include "types.h"

View File

@@ -34,7 +34,8 @@
/* auto detect between 32bit / 64bit */ /* auto detect between 32bit / 64bit */
#define HAS_SIZEOF_INT128_64BIT (defined(__SIZEOF_INT128__) && defined(__LP64__)) #define HAS_SIZEOF_INT128_64BIT (defined(__SIZEOF_INT128__) && defined(__LP64__))
#define HAS_MSVC_64BIT (defined(_MSC_VER) && defined(_M_X64)) #define HAS_MSVC_64BIT (defined(_MSC_VER) && defined(_M_X64))
#define HAS_GCC_4_4_64BIT (defined(__GNUC__) && defined(__LP64__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)))) #define HAS_GCC_4_4_64BIT (defined(__GNUC__) && defined(__LP64__) && \
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))))
#if (HAS_SIZEOF_INT128_64BIT || HAS_MSVC_64BIT || HAS_GCC_4_4_64BIT) #if (HAS_SIZEOF_INT128_64BIT || HAS_MSVC_64BIT || HAS_GCC_4_4_64BIT)
#define POLY130564 #define POLY130564

View File

@@ -4885,6 +4885,9 @@ static int ChachaAEADEncrypt(CYASSL* ssl, byte* out, const byte* input,
byte additional[CHACHA20_BLOCK_SIZE]; byte additional[CHACHA20_BLOCK_SIZE];
byte nonce[AEAD_NONCE_SZ]; byte nonce[AEAD_NONCE_SZ];
byte cipher[CHACHA20_256_KEY_SIZE]; /* generated key for poly1305 */ byte cipher[CHACHA20_256_KEY_SIZE]; /* generated key for poly1305 */
#ifdef CHACHA_AEAD_TEST
int i;
#endif
XMEMSET(tag, 0, sizeof(tag)); XMEMSET(tag, 0, sizeof(tag));
XMEMSET(nonce, 0, AEAD_NONCE_SZ); XMEMSET(nonce, 0, AEAD_NONCE_SZ);
@@ -4910,7 +4913,6 @@ static int ChachaAEADEncrypt(CYASSL* ssl, byte* out, const byte* input,
XMEMCPY(additional + AEAD_TYPE_OFFSET, additionalSrc, 3); XMEMCPY(additional + AEAD_TYPE_OFFSET, additionalSrc, 3);
#ifdef CHACHA_AEAD_TEST #ifdef CHACHA_AEAD_TEST
int i;
printf("Encrypt Additional : "); printf("Encrypt Additional : ");
for (i = 0; i < CHACHA20_BLOCK_SIZE; i++) { for (i = 0; i < CHACHA20_BLOCK_SIZE; i++) {
printf("%02x", additional[i]); printf("%02x", additional[i]);