Use stdint types a bit more

This commit is contained in:
Frank Denis
2016-02-27 16:33:22 +01:00
parent 4e9b0b67ce
commit 9fbb822281
15 changed files with 68 additions and 77 deletions
@@ -4,15 +4,16 @@ D. J. Bernstein
Public domain.
*/
#include <stdint.h>
#include <stdlib.h>
#include "crypto_core_hsalsa20.h"
#include "../../sodium/common.h"
#define ROUNDS 20
#define U32C(v) (v##U)
typedef unsigned int uint32;
static uint32 rotate(uint32 u,int c)
static uint32_t rotate(uint32_t u,int c)
{
return (u << c) | (u >> (32 - c));
}
@@ -24,7 +25,7 @@ int crypto_core_hsalsa20(
const unsigned char *c
)
{
uint32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
int i;
if (c == NULL) {
@@ -4,14 +4,15 @@ D. J. Bernstein
Public domain.
*/
#include <stdint.h>
#include <stdlib.h>
#include "crypto_core_salsa20.h"
#include "../../sodium/common.h"
#define ROUNDS 20
typedef unsigned int uint32;
static uint32 rotate(uint32 u,int c)
static uint32_t rotate(uint32_t u,int c)
{
return (u << c) | (u >> (32 - c));
}
@@ -23,8 +24,8 @@ int crypto_core_salsa20(
const unsigned char *c
)
{
uint32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
uint32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
int i;
j0 = x0 = LOAD32_LE(c + 0);
@@ -4,14 +4,15 @@ D. J. Bernstein
Public domain.
*/
#include <stdint.h>
#include <stdlib.h>
#include "crypto_core_salsa2012.h"
#include "../../sodium/common.h"
#define ROUNDS 12
typedef unsigned int uint32;
static uint32 rotate(uint32 u,int c)
static uint32_t rotate(uint32_t u,int c)
{
return (u << c) | (u >> (32 - c));
}
@@ -23,8 +24,8 @@ int crypto_core_salsa2012(
const unsigned char *c
)
{
uint32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
uint32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
int i;
j0 = x0 = LOAD32_LE(c + 0);
@@ -4,14 +4,15 @@ D. J. Bernstein
Public domain.
*/
#include <stdint.h>
#include <stdlib.h>
#include "crypto_core_salsa208.h"
#include "../../sodium/common.h"
#define ROUNDS 8
typedef unsigned int uint32;
static uint32 rotate(uint32 u,int c)
static uint32_t rotate(uint32_t u,int c)
{
return (u << c) | (u >> (32 - c));
}
@@ -23,8 +24,8 @@ int crypto_core_salsa208(
const unsigned char *c
)
{
uint32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
uint32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
uint32_t x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
uint32_t j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
int i;
j0 = x0 = LOAD32_LE(c + 0);
@@ -6,9 +6,10 @@
#ifndef fe_H
#define fe_H
#include "crypto_uint64.h"
#include <stdint.h>
#include <stdlib.h>
typedef crypto_uint64 fe[10];
typedef uint64_t fe[10];
/*
fe means field element.
@@ -12,12 +12,14 @@
extern "C" {
#endif
#include "crypto_uint64.h"
#include <stdint.h>
#include <stdlib.h>
#include "fe51_namespace.h"
typedef struct
{
crypto_uint64 v[5];
uint64_t v[5];
}
fe51;
@@ -3,51 +3,50 @@
*/
#include "fe.h"
#include "crypto_uint64.h"
#ifdef HAVE_AVX_ASM
static crypto_uint64 load_3(const unsigned char *in)
static uint64_t load_3(const unsigned char *in)
{
crypto_uint64 result;
result = (crypto_uint64) in[0];
result |= ((crypto_uint64) in[1]) << 8;
result |= ((crypto_uint64) in[2]) << 16;
uint64_t result;
result = (uint64_t) in[0];
result |= ((uint64_t) in[1]) << 8;
result |= ((uint64_t) in[2]) << 16;
return result;
}
static crypto_uint64 load_4(const unsigned char *in)
static uint64_t load_4(const unsigned char *in)
{
crypto_uint64 result;
result = (crypto_uint64) in[0];
result |= ((crypto_uint64) in[1]) << 8;
result |= ((crypto_uint64) in[2]) << 16;
result |= ((crypto_uint64) in[3]) << 24;
uint64_t result;
result = (uint64_t) in[0];
result |= ((uint64_t) in[1]) << 8;
result |= ((uint64_t) in[2]) << 16;
result |= ((uint64_t) in[3]) << 24;
return result;
}
void fe_frombytes(fe h,const unsigned char *s)
{
crypto_uint64 h0 = load_4(s);
crypto_uint64 h1 = load_3(s + 4) << 6;
crypto_uint64 h2 = load_3(s + 7) << 5;
crypto_uint64 h3 = load_3(s + 10) << 3;
crypto_uint64 h4 = load_3(s + 13) << 2;
crypto_uint64 h5 = load_4(s + 16);
crypto_uint64 h6 = load_3(s + 20) << 7;
crypto_uint64 h7 = load_3(s + 23) << 5;
crypto_uint64 h8 = load_3(s + 26) << 4;
crypto_uint64 h9 = (load_3(s + 29) & 8388607) << 2;
crypto_uint64 carry0;
crypto_uint64 carry1;
crypto_uint64 carry2;
crypto_uint64 carry3;
crypto_uint64 carry4;
crypto_uint64 carry5;
crypto_uint64 carry6;
crypto_uint64 carry7;
crypto_uint64 carry8;
crypto_uint64 carry9;
uint64_t h0 = load_4(s);
uint64_t h1 = load_3(s + 4) << 6;
uint64_t h2 = load_3(s + 7) << 5;
uint64_t h3 = load_3(s + 10) << 3;
uint64_t h4 = load_3(s + 13) << 2;
uint64_t h5 = load_4(s + 16);
uint64_t h6 = load_3(s + 20) << 7;
uint64_t h7 = load_3(s + 23) << 5;
uint64_t h8 = load_3(s + 26) << 4;
uint64_t h9 = (load_3(s + 29) & 8388607) << 2;
uint64_t carry0;
uint64_t carry1;
uint64_t carry2;
uint64_t carry3;
uint64_t carry4;
uint64_t carry5;
uint64_t carry6;
uint64_t carry7;
uint64_t carry8;
uint64_t carry9;
carry9 = h9 >> 25; h0 += carry9 * 19; h9 &= 0x1FFFFFF;
carry1 = h1 >> 25; h2 += carry1; h1 &= 0x1FFFFFF;
@@ -1,12 +1,9 @@
#include "crypto_shorthash_siphash24.h"
#include "crypto_uint64.h"
#include "crypto_uint32.h"
#include "crypto_uint8.h"
#include "../../sodium/common.h"
typedef crypto_uint64 u64;
typedef crypto_uint32 u32;
typedef crypto_uint8 u8;
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint8_t u8;
#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
@@ -1,10 +1,10 @@
#ifndef TYPES_H
#define TYPES_H
#include "crypto_uint32.h"
typedef crypto_uint32 uint32;
#include <inttypes.h>
#include <stdlib.h>
#include "crypto_uint64.h"
typedef crypto_uint64 uint64;
typedef uint32_t uint32;
typedef uint64_t uint64;
#endif
@@ -10,8 +10,6 @@ Public domain.
#ifndef HAVE_AMD64_ASM
typedef unsigned int uint32;
int crypto_stream_salsa20(
unsigned char *c,unsigned long long clen,
const unsigned char *n,
@@ -12,8 +12,6 @@ Public domain.
#ifndef HAVE_AMD64_ASM
typedef unsigned int uint32;
int crypto_stream_salsa20_xor_ic(
unsigned char *c,
const unsigned char *m,unsigned long long mlen,
@@ -8,8 +8,6 @@ Public domain.
#include "crypto_stream_salsa2012.h"
#include "utils.h"
typedef unsigned int uint32;
int crypto_stream_salsa2012(
unsigned char *c,unsigned long long clen,
const unsigned char *n,
@@ -8,8 +8,6 @@ Public domain.
#include "crypto_stream_salsa2012.h"
#include "utils.h"
typedef unsigned int uint32;
int crypto_stream_salsa2012_xor(
unsigned char *c,
const unsigned char *m,unsigned long long mlen,
@@ -8,8 +8,6 @@ Public domain.
#include "crypto_stream_salsa208.h"
#include "utils.h"
typedef unsigned int uint32;
int crypto_stream_salsa208(
unsigned char *c,unsigned long long clen,
const unsigned char *n,
@@ -8,8 +8,6 @@ Public domain.
#include "crypto_stream_salsa208.h"
#include "utils.h"
typedef unsigned int uint32;
int crypto_stream_salsa208_xor(
unsigned char *c,
const unsigned char *m,unsigned long long mlen,