Unpacked nacl-20110221 after processing by nacl-prepare-sources.

This only affects build_android, if nacl-gcc-prep is run then build/`uname -s` will be created.
This commit is contained in:
Daniel O'Connor 2012-02-24 17:11:30 +10:30
parent b053386b4f
commit bf9710fd5a
612 changed files with 102404 additions and 0 deletions

56
nacl/nacl-20110221/MACROS Normal file
View File

@ -0,0 +1,56 @@
crypto_verify
crypto_verify_BYTES
crypto_core
crypto_core_OUTPUTBYTES
crypto_core_INPUTBYTES
crypto_core_KEYBYTES
crypto_core_CONSTBYTES
crypto_hashblocks
crypto_hashblocks_STATEBYTES
crypto_hashblocks_BLOCKBYTES
crypto_hash
crypto_hash_BYTES
crypto_stream
crypto_stream_xor
crypto_stream_beforenm
crypto_stream_afternm
crypto_stream_xor_afternm
crypto_stream_KEYBYTES
crypto_stream_NONCEBYTES
crypto_stream_BEFORENMBYTES
crypto_onetimeauth
crypto_onetimeauth_verify
crypto_onetimeauth_BYTES
crypto_onetimeauth_KEYBYTES
crypto_auth
crypto_auth_verify
crypto_auth_BYTES
crypto_auth_KEYBYTES
crypto_secretbox
crypto_secretbox_open
crypto_secretbox_KEYBYTES
crypto_secretbox_NONCEBYTES
crypto_secretbox_ZEROBYTES
crypto_secretbox_BOXZEROBYTES
crypto_scalarmult
crypto_scalarmult_base
crypto_scalarmult_BYTES
crypto_scalarmult_SCALARBYTES
crypto_box
crypto_box_open
crypto_box_keypair
crypto_box_beforenm
crypto_box_afternm
crypto_box_open_afternm
crypto_box_PUBLICKEYBYTES
crypto_box_SECRETKEYBYTES
crypto_box_BEFORENMBYTES
crypto_box_NONCEBYTES
crypto_box_ZEROBYTES
crypto_box_BOXZEROBYTES
crypto_sign
crypto_sign_open
crypto_sign_keypair
crypto_sign_BYTES
crypto_sign_PUBLICKEYBYTES
crypto_sign_SECRETKEYBYTES

View File

@ -0,0 +1,11 @@
crypto_verify
crypto_core
crypto_hashblocks
crypto_hash
crypto_stream
crypto_onetimeauth
crypto_auth
crypto_secretbox
crypto_scalarmult
crypto_box
crypto_sign

View File

@ -0,0 +1,26 @@
extern int crypto_verify(const unsigned char *,const unsigned char *);
extern int crypto_core(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_hashblocks(unsigned char *,const unsigned char *,unsigned long long);
extern int crypto_hash(unsigned char *,const unsigned char *,unsigned long long);
extern int crypto_stream(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_beforenm(unsigned char *,const unsigned char *);
extern int crypto_stream_afternm(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_xor_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_onetimeauth(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_onetimeauth_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_auth(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_auth_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_secretbox(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_secretbox_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_scalarmult(unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_scalarmult_base(unsigned char *,const unsigned char *);
extern int crypto_box(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_box_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_box_keypair(unsigned char *,unsigned char *);
extern int crypto_box_beforenm(unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_box_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_box_open_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_sign(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_sign_open(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_sign_keypair(unsigned char *,unsigned char *);

View File

@ -0,0 +1,17 @@
extern std::string crypto_auth(const std::string &,const std::string &);
extern void crypto_auth_verify(const std::string &,const std::string &,const std::string &);
extern std::string crypto_box(const std::string &,const std::string &,const std::string &,const std::string &);
extern std::string crypto_box_open(const std::string &,const std::string &,const std::string &,const std::string &);
extern std::string crypto_box_keypair(std::string *);
extern std::string crypto_hash(const std::string &);
extern std::string crypto_onetimeauth(const std::string &,const std::string &);
extern void crypto_onetimeauth_verify(const std::string &,const std::string &,const std::string &);
extern std::string crypto_scalarmult(const std::string &,const std::string &);
extern std::string crypto_scalarmult_base(const std::string &);
extern std::string crypto_secretbox(const std::string &,const std::string &,const std::string &);
extern std::string crypto_secretbox_open(const std::string &,const std::string &,const std::string &);
extern std::string crypto_stream(size_t,const std::string &,const std::string &);
extern std::string crypto_stream_xor(const std::string &,const std::string &,const std::string &);
extern std::string crypto_sign(const std::string &,const std::string &);
extern std::string crypto_sign_open(const std::string &,const std::string &);
extern std::string crypto_sign_keypair(std::string *);

View File

@ -0,0 +1,56 @@
crypto_verify
crypto_verify_BYTES
crypto_core
crypto_core_OUTPUTBYTES
crypto_core_INPUTBYTES
crypto_core_KEYBYTES
crypto_core_CONSTBYTES
crypto_hashblocks
crypto_hashblocks_STATEBYTES
crypto_hashblocks_BLOCKBYTES
crypto_hash
crypto_hash_BYTES
crypto_stream
crypto_stream_xor
crypto_stream_beforenm
crypto_stream_afternm
crypto_stream_xor_afternm
crypto_stream_KEYBYTES
crypto_stream_NONCEBYTES
crypto_stream_BEFORENMBYTES
crypto_onetimeauth
crypto_onetimeauth_verify
crypto_onetimeauth_BYTES
crypto_onetimeauth_KEYBYTES
crypto_auth
crypto_auth_verify
crypto_auth_BYTES
crypto_auth_KEYBYTES
crypto_secretbox
crypto_secretbox_open
crypto_secretbox_KEYBYTES
crypto_secretbox_NONCEBYTES
crypto_secretbox_ZEROBYTES
crypto_secretbox_BOXZEROBYTES
crypto_scalarmult
crypto_scalarmult_base
crypto_scalarmult_BYTES
crypto_scalarmult_SCALARBYTES
crypto_box
crypto_box_open
crypto_box_keypair
crypto_box_beforenm
crypto_box_afternm
crypto_box_open_afternm
crypto_box_PUBLICKEYBYTES
crypto_box_SECRETKEYBYTES
crypto_box_BEFORENMBYTES
crypto_box_NONCEBYTES
crypto_box_ZEROBYTES
crypto_box_BOXZEROBYTES
crypto_sign
crypto_sign_open
crypto_sign_keypair
crypto_sign_BYTES
crypto_sign_PUBLICKEYBYTES
crypto_sign_SECRETKEYBYTES

View File

@ -0,0 +1,26 @@
extern int crypto_verify(const unsigned char *,const unsigned char *);
extern int crypto_core(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_hashblocks(unsigned char *,const unsigned char *,unsigned long long);
extern int crypto_hash(unsigned char *,const unsigned char *,unsigned long long);
extern int crypto_stream(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_beforenm(unsigned char *,const unsigned char *);
extern int crypto_stream_afternm(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_xor_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_onetimeauth(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_onetimeauth_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_auth(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_auth_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_secretbox(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_secretbox_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_scalarmult(unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_scalarmult_base(unsigned char *,const unsigned char *);
extern int crypto_box(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_box_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_box_keypair(unsigned char *,unsigned char *);
extern int crypto_box_beforenm(unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_box_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_box_open_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_sign(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_sign_open(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_sign_keypair(unsigned char *,unsigned char *);

View File

@ -0,0 +1,17 @@
extern std::string crypto_auth(const std::string &,const std::string &);
extern void crypto_auth_verify(const std::string &,const std::string &,const std::string &);
extern std::string crypto_box(const std::string &,const std::string &,const std::string &,const std::string &);
extern std::string crypto_box_open(const std::string &,const std::string &,const std::string &,const std::string &);
extern std::string crypto_box_keypair(std::string *);
extern std::string crypto_hash(const std::string &);
extern std::string crypto_onetimeauth(const std::string &,const std::string &);
extern void crypto_onetimeauth_verify(const std::string &,const std::string &,const std::string &);
extern std::string crypto_scalarmult(const std::string &,const std::string &);
extern std::string crypto_scalarmult_base(const std::string &);
extern std::string crypto_secretbox(const std::string &,const std::string &,const std::string &);
extern std::string crypto_secretbox_open(const std::string &,const std::string &,const std::string &);
extern std::string crypto_stream(size_t,const std::string &,const std::string &);
extern std::string crypto_stream_xor(const std::string &,const std::string &,const std::string &);
extern std::string crypto_sign(const std::string &,const std::string &);
extern std::string crypto_sign_open(const std::string &,const std::string &);
extern std::string crypto_sign_keypair(std::string *);

View File

@ -0,0 +1,3 @@
#define CRYPTO_SECRETKEYBYTES 64
#define CRYPTO_PUBLICKEYBYTES 32
#define CRYPTO_BYTES 64

View File

@ -0,0 +1,32 @@
#ifndef crypto_auth_hmacsha256_H
#define crypto_auth_hmacsha256_H
#define crypto_auth_hmacsha256_ref_BYTES 32
#define crypto_auth_hmacsha256_ref_KEYBYTES 32
#ifdef __cplusplus
#include <string>
extern std::string crypto_auth_hmacsha256_ref(const std::string &,const std::string &);
extern void crypto_auth_hmacsha256_ref_verify(const std::string &,const std::string &,const std::string &);
extern "C" {
#endif
extern int crypto_auth_hmacsha256_ref(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_auth_hmacsha256_ref_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_auth_hmacsha256 crypto_auth_hmacsha256_ref
/* POTATO crypto_auth_hmacsha256_ref crypto_auth_hmacsha256_ref crypto_auth_hmacsha256 */
#define crypto_auth_hmacsha256_verify crypto_auth_hmacsha256_ref_verify
/* POTATO crypto_auth_hmacsha256_ref_verify crypto_auth_hmacsha256_ref crypto_auth_hmacsha256 */
#define crypto_auth_hmacsha256_BYTES crypto_auth_hmacsha256_ref_BYTES
/* POTATO crypto_auth_hmacsha256_ref_BYTES crypto_auth_hmacsha256_ref crypto_auth_hmacsha256 */
#define crypto_auth_hmacsha256_KEYBYTES crypto_auth_hmacsha256_ref_KEYBYTES
/* POTATO crypto_auth_hmacsha256_ref_KEYBYTES crypto_auth_hmacsha256_ref crypto_auth_hmacsha256 */
#define crypto_auth_hmacsha256_IMPLEMENTATION "crypto_auth/hmacsha256/ref"
#ifndef crypto_auth_hmacsha256_ref_VERSION
#define crypto_auth_hmacsha256_ref_VERSION "-"
#endif
#define crypto_auth_hmacsha256_VERSION crypto_auth_hmacsha256_ref_VERSION
#endif

View File

@ -0,0 +1,2 @@
#define CRYPTO_BYTES 32
#define CRYPTO_KEYBYTES 32

View File

@ -0,0 +1,18 @@
#ifndef crypto_auth_H
#define crypto_auth_H
#include "crypto_auth_hmacsha256.h"
#define crypto_auth crypto_auth_hmacsha256
/* CHEESEBURGER crypto_auth_hmacsha256 */
#define crypto_auth_verify crypto_auth_hmacsha256_verify
/* CHEESEBURGER crypto_auth_hmacsha256_verify */
#define crypto_auth_BYTES crypto_auth_hmacsha256_BYTES
/* CHEESEBURGER crypto_auth_hmacsha256_BYTES */
#define crypto_auth_KEYBYTES crypto_auth_hmacsha256_KEYBYTES
/* CHEESEBURGER crypto_auth_hmacsha256_KEYBYTES */
#define crypto_auth_PRIMITIVE "hmacsha256"
#define crypto_auth_IMPLEMENTATION crypto_auth_hmacsha256_IMPLEMENTATION
#define crypto_auth_VERSION crypto_auth_hmacsha256_VERSION
#endif

View File

@ -0,0 +1,83 @@
/*
* 20080913
* D. J. Bernstein
* Public domain.
* */
#include "crypto_hashblocks_sha256.h"
#include "crypto_auth.h"
#define blocks crypto_hashblocks_sha256
typedef unsigned int uint32;
static const char iv[32] = {
0x6a,0x09,0xe6,0x67,
0xbb,0x67,0xae,0x85,
0x3c,0x6e,0xf3,0x72,
0xa5,0x4f,0xf5,0x3a,
0x51,0x0e,0x52,0x7f,
0x9b,0x05,0x68,0x8c,
0x1f,0x83,0xd9,0xab,
0x5b,0xe0,0xcd,0x19,
} ;
int crypto_auth(unsigned char *out,const unsigned char *in,unsigned long long inlen,const unsigned char *k)
{
unsigned char h[32];
unsigned char padded[128];
int i;
unsigned long long bits = 512 + (inlen << 3);
for (i = 0;i < 32;++i) h[i] = iv[i];
for (i = 0;i < 32;++i) padded[i] = k[i] ^ 0x36;
for (i = 32;i < 64;++i) padded[i] = 0x36;
blocks(h,padded,64);
blocks(h,in,inlen);
in += inlen;
inlen &= 63;
in -= inlen;
for (i = 0;i < inlen;++i) padded[i] = in[i];
padded[inlen] = 0x80;
if (inlen < 56) {
for (i = inlen + 1;i < 56;++i) padded[i] = 0;
padded[56] = bits >> 56;
padded[57] = bits >> 48;
padded[58] = bits >> 40;
padded[59] = bits >> 32;
padded[60] = bits >> 24;
padded[61] = bits >> 16;
padded[62] = bits >> 8;
padded[63] = bits;
blocks(h,padded,64);
} else {
for (i = inlen + 1;i < 120;++i) padded[i] = 0;
padded[120] = bits >> 56;
padded[121] = bits >> 48;
padded[122] = bits >> 40;
padded[123] = bits >> 32;
padded[124] = bits >> 24;
padded[125] = bits >> 16;
padded[126] = bits >> 8;
padded[127] = bits;
blocks(h,padded,128);
}
for (i = 0;i < 32;++i) padded[i] = k[i] ^ 0x5c;
for (i = 32;i < 64;++i) padded[i] = 0x5c;
for (i = 0;i < 32;++i) padded[64 + i] = h[i];
for (i = 0;i < 32;++i) out[i] = iv[i];
for (i = 32;i < 64;++i) padded[64 + i] = 0;
padded[64 + 32] = 0x80;
padded[64 + 62] = 3;
blocks(out,padded,128);
return 0;
}

View File

@ -0,0 +1,9 @@
#include "crypto_verify_32.h"
#include "crypto_auth.h"
int crypto_auth_verify(const unsigned char *h,const unsigned char *in,unsigned long long inlen,const unsigned char *k)
{
unsigned char correct[32];
crypto_auth(correct,in,inlen,k);
return crypto_verify_32(h,correct);
}

View File

@ -0,0 +1,32 @@
#ifndef crypto_auth_hmacsha512256_H
#define crypto_auth_hmacsha512256_H
#define crypto_auth_hmacsha512256_ref_BYTES 32
#define crypto_auth_hmacsha512256_ref_KEYBYTES 32
#ifdef __cplusplus
#include <string>
extern std::string crypto_auth_hmacsha512256_ref(const std::string &,const std::string &);
extern void crypto_auth_hmacsha512256_ref_verify(const std::string &,const std::string &,const std::string &);
extern "C" {
#endif
extern int crypto_auth_hmacsha512256_ref(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_auth_hmacsha512256_ref_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_auth_hmacsha512256 crypto_auth_hmacsha512256_ref
/* POTATO crypto_auth_hmacsha512256_ref crypto_auth_hmacsha512256_ref crypto_auth_hmacsha512256 */
#define crypto_auth_hmacsha512256_verify crypto_auth_hmacsha512256_ref_verify
/* POTATO crypto_auth_hmacsha512256_ref_verify crypto_auth_hmacsha512256_ref crypto_auth_hmacsha512256 */
#define crypto_auth_hmacsha512256_BYTES crypto_auth_hmacsha512256_ref_BYTES
/* POTATO crypto_auth_hmacsha512256_ref_BYTES crypto_auth_hmacsha512256_ref crypto_auth_hmacsha512256 */
#define crypto_auth_hmacsha512256_KEYBYTES crypto_auth_hmacsha512256_ref_KEYBYTES
/* POTATO crypto_auth_hmacsha512256_ref_KEYBYTES crypto_auth_hmacsha512256_ref crypto_auth_hmacsha512256 */
#define crypto_auth_hmacsha512256_IMPLEMENTATION "crypto_auth/hmacsha512256/ref"
#ifndef crypto_auth_hmacsha512256_ref_VERSION
#define crypto_auth_hmacsha512256_ref_VERSION "-"
#endif
#define crypto_auth_hmacsha512256_VERSION crypto_auth_hmacsha512256_ref_VERSION
#endif

View File

@ -0,0 +1,2 @@
#define CRYPTO_BYTES 32
#define CRYPTO_KEYBYTES 32

View File

@ -0,0 +1,18 @@
#ifndef crypto_auth_H
#define crypto_auth_H
#include "crypto_auth_hmacsha512256.h"
#define crypto_auth crypto_auth_hmacsha512256
/* CHEESEBURGER crypto_auth_hmacsha512256 */
#define crypto_auth_verify crypto_auth_hmacsha512256_verify
/* CHEESEBURGER crypto_auth_hmacsha512256_verify */
#define crypto_auth_BYTES crypto_auth_hmacsha512256_BYTES
/* CHEESEBURGER crypto_auth_hmacsha512256_BYTES */
#define crypto_auth_KEYBYTES crypto_auth_hmacsha512256_KEYBYTES
/* CHEESEBURGER crypto_auth_hmacsha512256_KEYBYTES */
#define crypto_auth_PRIMITIVE "hmacsha512256"
#define crypto_auth_IMPLEMENTATION crypto_auth_hmacsha512256_IMPLEMENTATION
#define crypto_auth_VERSION crypto_auth_hmacsha512256_VERSION
#endif

View File

@ -0,0 +1,86 @@
/*
* 20080913
* D. J. Bernstein
* Public domain.
* */
#include "crypto_hashblocks_sha512.h"
#include "crypto_auth.h"
#define blocks crypto_hashblocks_sha512
typedef unsigned long long uint64;
static const unsigned char iv[64] = {
0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08,
0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b,
0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b,
0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1,
0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1,
0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f,
0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b,
0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79
} ;
int crypto_auth(unsigned char *out,const unsigned char *in,unsigned long long inlen,const unsigned char *k)
{
unsigned char h[64];
unsigned char padded[256];
int i;
unsigned long long bytes = 128 + inlen;
for (i = 0;i < 64;++i) h[i] = iv[i];
for (i = 0;i < 32;++i) padded[i] = k[i] ^ 0x36;
for (i = 32;i < 128;++i) padded[i] = 0x36;
blocks(h,padded,128);
blocks(h,in,inlen);
in += inlen;
inlen &= 127;
in -= inlen;
for (i = 0;i < inlen;++i) padded[i] = in[i];
padded[inlen] = 0x80;
if (inlen < 112) {
for (i = inlen + 1;i < 119;++i) padded[i] = 0;
padded[119] = bytes >> 61;
padded[120] = bytes >> 53;
padded[121] = bytes >> 45;
padded[122] = bytes >> 37;
padded[123] = bytes >> 29;
padded[124] = bytes >> 21;
padded[125] = bytes >> 13;
padded[126] = bytes >> 5;
padded[127] = bytes << 3;
blocks(h,padded,128);
} else {
for (i = inlen + 1;i < 247;++i) padded[i] = 0;
padded[247] = bytes >> 61;
padded[248] = bytes >> 53;
padded[249] = bytes >> 45;
padded[250] = bytes >> 37;
padded[251] = bytes >> 29;
padded[252] = bytes >> 21;
padded[253] = bytes >> 13;
padded[254] = bytes >> 5;
padded[255] = bytes << 3;
blocks(h,padded,256);
}
for (i = 0;i < 32;++i) padded[i] = k[i] ^ 0x5c;
for (i = 32;i < 128;++i) padded[i] = 0x5c;
for (i = 0;i < 64;++i) padded[128 + i] = h[i];
for (i = 0;i < 64;++i) h[i] = iv[i];
for (i = 64;i < 128;++i) padded[128 + i] = 0;
padded[128 + 64] = 0x80;
padded[128 + 126] = 6;
blocks(h,padded,256);
for (i = 0;i < 32;++i) out[i] = h[i];
return 0;
}

View File

@ -0,0 +1,9 @@
#include "crypto_verify_32.h"
#include "crypto_auth.h"
int crypto_auth_verify(const unsigned char *h,const unsigned char *in,unsigned long long inlen,const unsigned char *k)
{
unsigned char correct[32];
crypto_auth(correct,in,inlen,k);
return crypto_verify_32(h,correct);
}

View File

@ -0,0 +1,57 @@
#ifndef crypto_box_curve25519xsalsa20poly1305_H
#define crypto_box_curve25519xsalsa20poly1305_H
#define crypto_box_curve25519xsalsa20poly1305_ref_PUBLICKEYBYTES 32
#define crypto_box_curve25519xsalsa20poly1305_ref_SECRETKEYBYTES 32
#define crypto_box_curve25519xsalsa20poly1305_ref_BEFORENMBYTES 32
#define crypto_box_curve25519xsalsa20poly1305_ref_NONCEBYTES 24
#define crypto_box_curve25519xsalsa20poly1305_ref_ZEROBYTES 32
#define crypto_box_curve25519xsalsa20poly1305_ref_BOXZEROBYTES 16
#ifdef __cplusplus
#include <string>
extern std::string crypto_box_curve25519xsalsa20poly1305_ref(const std::string &,const std::string &,const std::string &,const std::string &);
extern std::string crypto_box_curve25519xsalsa20poly1305_ref_open(const std::string &,const std::string &,const std::string &,const std::string &);
extern std::string crypto_box_curve25519xsalsa20poly1305_ref_keypair(std::string *);
extern "C" {
#endif
extern int crypto_box_curve25519xsalsa20poly1305_ref(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_box_curve25519xsalsa20poly1305_ref_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_box_curve25519xsalsa20poly1305_ref_keypair(unsigned char *,unsigned char *);
extern int crypto_box_curve25519xsalsa20poly1305_ref_beforenm(unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_box_curve25519xsalsa20poly1305_ref_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_box_curve25519xsalsa20poly1305_ref_open_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_box_curve25519xsalsa20poly1305 crypto_box_curve25519xsalsa20poly1305_ref
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_open crypto_box_curve25519xsalsa20poly1305_ref_open
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_open crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_keypair crypto_box_curve25519xsalsa20poly1305_ref_keypair
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_keypair crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_beforenm crypto_box_curve25519xsalsa20poly1305_ref_beforenm
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_beforenm crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_afternm crypto_box_curve25519xsalsa20poly1305_ref_afternm
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_afternm crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_open_afternm crypto_box_curve25519xsalsa20poly1305_ref_open_afternm
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_open_afternm crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_ref_PUBLICKEYBYTES
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_ref_SECRETKEYBYTES
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_ref_BEFORENMBYTES
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_ref_NONCEBYTES
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ref_ZEROBYTES
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_ref_BOXZEROBYTES
/* POTATO crypto_box_curve25519xsalsa20poly1305_ref_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_ref crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_curve25519xsalsa20poly1305_IMPLEMENTATION "crypto_box/curve25519xsalsa20poly1305/ref"
#ifndef crypto_box_curve25519xsalsa20poly1305_ref_VERSION
#define crypto_box_curve25519xsalsa20poly1305_ref_VERSION "-"
#endif
#define crypto_box_curve25519xsalsa20poly1305_VERSION crypto_box_curve25519xsalsa20poly1305_ref_VERSION
#endif

View File

@ -0,0 +1,22 @@
#include "crypto_secretbox_xsalsa20poly1305.h"
#include "crypto_box.h"
int crypto_box_afternm(
unsigned char *c,
const unsigned char *m,unsigned long long mlen,
const unsigned char *n,
const unsigned char *k
)
{
return crypto_secretbox_xsalsa20poly1305(c,m,mlen,n,k);
}
int crypto_box_open_afternm(
unsigned char *m,
const unsigned char *c,unsigned long long clen,
const unsigned char *n,
const unsigned char *k
)
{
return crypto_secretbox_xsalsa20poly1305_open(m,c,clen,n,k);
}

View File

@ -0,0 +1,6 @@
#define CRYPTO_PUBLICKEYBYTES 32
#define CRYPTO_SECRETKEYBYTES 32
#define CRYPTO_BEFORENMBYTES 32
#define CRYPTO_NONCEBYTES 24
#define CRYPTO_ZEROBYTES 32
#define CRYPTO_BOXZEROBYTES 16

View File

@ -0,0 +1,17 @@
#include "crypto_core_hsalsa20.h"
#include "crypto_scalarmult_curve25519.h"
#include "crypto_box.h"
static const unsigned char sigma[16] = "expand 32-byte k";
static const unsigned char n[16] = {0};
int crypto_box_beforenm(
unsigned char *k,
const unsigned char *pk,
const unsigned char *sk
)
{
unsigned char s[32];
crypto_scalarmult_curve25519(s,sk,pk);
return crypto_core_hsalsa20(k,n,s,sigma);
}

View File

@ -0,0 +1,27 @@
#include "crypto_box.h"
int crypto_box(
unsigned char *c,
const unsigned char *m,unsigned long long mlen,
const unsigned char *n,
const unsigned char *pk,
const unsigned char *sk
)
{
unsigned char k[crypto_box_BEFORENMBYTES];
crypto_box_beforenm(k,pk,sk);
return crypto_box_afternm(c,m,mlen,n,k);
}
int crypto_box_open(
unsigned char *m,
const unsigned char *c,unsigned long long clen,
const unsigned char *n,
const unsigned char *pk,
const unsigned char *sk
)
{
unsigned char k[crypto_box_BEFORENMBYTES];
crypto_box_beforenm(k,pk,sk);
return crypto_box_open_afternm(m,c,clen,n,k);
}

View File

@ -0,0 +1,34 @@
#ifndef crypto_box_H
#define crypto_box_H
#include "crypto_box_curve25519xsalsa20poly1305.h"
#define crypto_box crypto_box_curve25519xsalsa20poly1305
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305 */
#define crypto_box_open crypto_box_curve25519xsalsa20poly1305_open
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_open */
#define crypto_box_keypair crypto_box_curve25519xsalsa20poly1305_keypair
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_keypair */
#define crypto_box_beforenm crypto_box_curve25519xsalsa20poly1305_beforenm
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_beforenm */
#define crypto_box_afternm crypto_box_curve25519xsalsa20poly1305_afternm
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_afternm */
#define crypto_box_open_afternm crypto_box_curve25519xsalsa20poly1305_open_afternm
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_open_afternm */
#define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES */
#define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES */
#define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES */
#define crypto_box_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_NONCEBYTES
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_NONCEBYTES */
#define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_ZEROBYTES */
#define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES
/* CHEESEBURGER crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES */
#define crypto_box_PRIMITIVE "curve25519xsalsa20poly1305"
#define crypto_box_IMPLEMENTATION crypto_box_curve25519xsalsa20poly1305_IMPLEMENTATION
#define crypto_box_VERSION crypto_box_curve25519xsalsa20poly1305_VERSION
#endif

View File

@ -0,0 +1,12 @@
#include "crypto_scalarmult_curve25519.h"
#include "crypto_box.h"
#include "randombytes.h"
int crypto_box_keypair(
unsigned char *pk,
unsigned char *sk
)
{
randombytes(sk,32);
return crypto_scalarmult_curve25519_base(pk,sk);
}

View File

@ -0,0 +1,33 @@
#ifndef crypto_core_hsalsa20_H
#define crypto_core_hsalsa20_H
#define crypto_core_hsalsa20_ref_OUTPUTBYTES 32
#define crypto_core_hsalsa20_ref_INPUTBYTES 16
#define crypto_core_hsalsa20_ref_KEYBYTES 32
#define crypto_core_hsalsa20_ref_CONSTBYTES 16
#ifdef __cplusplus
#include <string>
extern "C" {
#endif
extern int crypto_core_hsalsa20_ref(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_core_hsalsa20 crypto_core_hsalsa20_ref
/* POTATO crypto_core_hsalsa20_ref crypto_core_hsalsa20_ref crypto_core_hsalsa20 */
#define crypto_core_hsalsa20_OUTPUTBYTES crypto_core_hsalsa20_ref_OUTPUTBYTES
/* POTATO crypto_core_hsalsa20_ref_OUTPUTBYTES crypto_core_hsalsa20_ref crypto_core_hsalsa20 */
#define crypto_core_hsalsa20_INPUTBYTES crypto_core_hsalsa20_ref_INPUTBYTES
/* POTATO crypto_core_hsalsa20_ref_INPUTBYTES crypto_core_hsalsa20_ref crypto_core_hsalsa20 */
#define crypto_core_hsalsa20_KEYBYTES crypto_core_hsalsa20_ref_KEYBYTES
/* POTATO crypto_core_hsalsa20_ref_KEYBYTES crypto_core_hsalsa20_ref crypto_core_hsalsa20 */
#define crypto_core_hsalsa20_CONSTBYTES crypto_core_hsalsa20_ref_CONSTBYTES
/* POTATO crypto_core_hsalsa20_ref_CONSTBYTES crypto_core_hsalsa20_ref crypto_core_hsalsa20 */
#define crypto_core_hsalsa20_IMPLEMENTATION "crypto_core/hsalsa20/ref"
#ifndef crypto_core_hsalsa20_ref_VERSION
#define crypto_core_hsalsa20_ref_VERSION "-"
#endif
#define crypto_core_hsalsa20_VERSION crypto_core_hsalsa20_ref_VERSION
#endif

View File

@ -0,0 +1,4 @@
#define CRYPTO_OUTPUTBYTES 32
#define CRYPTO_INPUTBYTES 16
#define CRYPTO_KEYBYTES 32
#define CRYPTO_CONSTBYTES 16

View File

@ -0,0 +1,135 @@
/*
version 20080912
D. J. Bernstein
Public domain.
*/
#include "crypto_core.h"
#define ROUNDS 20
typedef unsigned int uint32;
static uint32 rotate(uint32 u,int c)
{
return (u << c) | (u >> (32 - c));
}
static uint32 load_littleendian(const unsigned char *x)
{
return
(uint32) (x[0]) \
| (((uint32) (x[1])) << 8) \
| (((uint32) (x[2])) << 16) \
| (((uint32) (x[3])) << 24)
;
}
static void store_littleendian(unsigned char *x,uint32 u)
{
x[0] = u; u >>= 8;
x[1] = u; u >>= 8;
x[2] = u; u >>= 8;
x[3] = u;
}
int crypto_core(
unsigned char *out,
const unsigned char *in,
const unsigned char *k,
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;
int i;
j0 = x0 = load_littleendian(c + 0);
j1 = x1 = load_littleendian(k + 0);
j2 = x2 = load_littleendian(k + 4);
j3 = x3 = load_littleendian(k + 8);
j4 = x4 = load_littleendian(k + 12);
j5 = x5 = load_littleendian(c + 4);
j6 = x6 = load_littleendian(in + 0);
j7 = x7 = load_littleendian(in + 4);
j8 = x8 = load_littleendian(in + 8);
j9 = x9 = load_littleendian(in + 12);
j10 = x10 = load_littleendian(c + 8);
j11 = x11 = load_littleendian(k + 16);
j12 = x12 = load_littleendian(k + 20);
j13 = x13 = load_littleendian(k + 24);
j14 = x14 = load_littleendian(k + 28);
j15 = x15 = load_littleendian(c + 12);
for (i = ROUNDS;i > 0;i -= 2) {
x4 ^= rotate( x0+x12, 7);
x8 ^= rotate( x4+ x0, 9);
x12 ^= rotate( x8+ x4,13);
x0 ^= rotate(x12+ x8,18);
x9 ^= rotate( x5+ x1, 7);
x13 ^= rotate( x9+ x5, 9);
x1 ^= rotate(x13+ x9,13);
x5 ^= rotate( x1+x13,18);
x14 ^= rotate(x10+ x6, 7);
x2 ^= rotate(x14+x10, 9);
x6 ^= rotate( x2+x14,13);
x10 ^= rotate( x6+ x2,18);
x3 ^= rotate(x15+x11, 7);
x7 ^= rotate( x3+x15, 9);
x11 ^= rotate( x7+ x3,13);
x15 ^= rotate(x11+ x7,18);
x1 ^= rotate( x0+ x3, 7);
x2 ^= rotate( x1+ x0, 9);
x3 ^= rotate( x2+ x1,13);
x0 ^= rotate( x3+ x2,18);
x6 ^= rotate( x5+ x4, 7);
x7 ^= rotate( x6+ x5, 9);
x4 ^= rotate( x7+ x6,13);
x5 ^= rotate( x4+ x7,18);
x11 ^= rotate(x10+ x9, 7);
x8 ^= rotate(x11+x10, 9);
x9 ^= rotate( x8+x11,13);
x10 ^= rotate( x9+ x8,18);
x12 ^= rotate(x15+x14, 7);
x13 ^= rotate(x12+x15, 9);
x14 ^= rotate(x13+x12,13);
x15 ^= rotate(x14+x13,18);
}
x0 += j0;
x1 += j1;
x2 += j2;
x3 += j3;
x4 += j4;
x5 += j5;
x6 += j6;
x7 += j7;
x8 += j8;
x9 += j9;
x10 += j10;
x11 += j11;
x12 += j12;
x13 += j13;
x14 += j14;
x15 += j15;
x0 -= load_littleendian(c + 0);
x5 -= load_littleendian(c + 4);
x10 -= load_littleendian(c + 8);
x15 -= load_littleendian(c + 12);
x6 -= load_littleendian(in + 0);
x7 -= load_littleendian(in + 4);
x8 -= load_littleendian(in + 8);
x9 -= load_littleendian(in + 12);
store_littleendian(out + 0,x0);
store_littleendian(out + 4,x5);
store_littleendian(out + 8,x10);
store_littleendian(out + 12,x15);
store_littleendian(out + 16,x6);
store_littleendian(out + 20,x7);
store_littleendian(out + 24,x8);
store_littleendian(out + 28,x9);
return 0;
}

View File

@ -0,0 +1,20 @@
#ifndef crypto_core_H
#define crypto_core_H
#include "crypto_core_hsalsa20.h"
#define crypto_core crypto_core_hsalsa20
/* CHEESEBURGER crypto_core_hsalsa20 */
#define crypto_core_OUTPUTBYTES crypto_core_hsalsa20_OUTPUTBYTES
/* CHEESEBURGER crypto_core_hsalsa20_OUTPUTBYTES */
#define crypto_core_INPUTBYTES crypto_core_hsalsa20_INPUTBYTES
/* CHEESEBURGER crypto_core_hsalsa20_INPUTBYTES */
#define crypto_core_KEYBYTES crypto_core_hsalsa20_KEYBYTES
/* CHEESEBURGER crypto_core_hsalsa20_KEYBYTES */
#define crypto_core_CONSTBYTES crypto_core_hsalsa20_CONSTBYTES
/* CHEESEBURGER crypto_core_hsalsa20_CONSTBYTES */
#define crypto_core_PRIMITIVE "hsalsa20"
#define crypto_core_IMPLEMENTATION crypto_core_hsalsa20_IMPLEMENTATION
#define crypto_core_VERSION crypto_core_hsalsa20_VERSION
#endif

View File

@ -0,0 +1 @@
Daniel J. Bernstein

View File

@ -0,0 +1,33 @@
#ifndef crypto_core_salsa20_H
#define crypto_core_salsa20_H
#define crypto_core_salsa20_ref_OUTPUTBYTES 64
#define crypto_core_salsa20_ref_INPUTBYTES 16
#define crypto_core_salsa20_ref_KEYBYTES 32
#define crypto_core_salsa20_ref_CONSTBYTES 16
#ifdef __cplusplus
#include <string>
extern "C" {
#endif
extern int crypto_core_salsa20_ref(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_core_salsa20 crypto_core_salsa20_ref
/* POTATO crypto_core_salsa20_ref crypto_core_salsa20_ref crypto_core_salsa20 */
#define crypto_core_salsa20_OUTPUTBYTES crypto_core_salsa20_ref_OUTPUTBYTES
/* POTATO crypto_core_salsa20_ref_OUTPUTBYTES crypto_core_salsa20_ref crypto_core_salsa20 */
#define crypto_core_salsa20_INPUTBYTES crypto_core_salsa20_ref_INPUTBYTES
/* POTATO crypto_core_salsa20_ref_INPUTBYTES crypto_core_salsa20_ref crypto_core_salsa20 */
#define crypto_core_salsa20_KEYBYTES crypto_core_salsa20_ref_KEYBYTES
/* POTATO crypto_core_salsa20_ref_KEYBYTES crypto_core_salsa20_ref crypto_core_salsa20 */
#define crypto_core_salsa20_CONSTBYTES crypto_core_salsa20_ref_CONSTBYTES
/* POTATO crypto_core_salsa20_ref_CONSTBYTES crypto_core_salsa20_ref crypto_core_salsa20 */
#define crypto_core_salsa20_IMPLEMENTATION "crypto_core/salsa20/ref"
#ifndef crypto_core_salsa20_ref_VERSION
#define crypto_core_salsa20_ref_VERSION "-"
#endif
#define crypto_core_salsa20_VERSION crypto_core_salsa20_ref_VERSION
#endif

View File

@ -0,0 +1,33 @@
#ifndef crypto_core_salsa2012_H
#define crypto_core_salsa2012_H
#define crypto_core_salsa2012_ref_OUTPUTBYTES 64
#define crypto_core_salsa2012_ref_INPUTBYTES 16
#define crypto_core_salsa2012_ref_KEYBYTES 32
#define crypto_core_salsa2012_ref_CONSTBYTES 16
#ifdef __cplusplus
#include <string>
extern "C" {
#endif
extern int crypto_core_salsa2012_ref(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_core_salsa2012 crypto_core_salsa2012_ref
/* POTATO crypto_core_salsa2012_ref crypto_core_salsa2012_ref crypto_core_salsa2012 */
#define crypto_core_salsa2012_OUTPUTBYTES crypto_core_salsa2012_ref_OUTPUTBYTES
/* POTATO crypto_core_salsa2012_ref_OUTPUTBYTES crypto_core_salsa2012_ref crypto_core_salsa2012 */
#define crypto_core_salsa2012_INPUTBYTES crypto_core_salsa2012_ref_INPUTBYTES
/* POTATO crypto_core_salsa2012_ref_INPUTBYTES crypto_core_salsa2012_ref crypto_core_salsa2012 */
#define crypto_core_salsa2012_KEYBYTES crypto_core_salsa2012_ref_KEYBYTES
/* POTATO crypto_core_salsa2012_ref_KEYBYTES crypto_core_salsa2012_ref crypto_core_salsa2012 */
#define crypto_core_salsa2012_CONSTBYTES crypto_core_salsa2012_ref_CONSTBYTES
/* POTATO crypto_core_salsa2012_ref_CONSTBYTES crypto_core_salsa2012_ref crypto_core_salsa2012 */
#define crypto_core_salsa2012_IMPLEMENTATION "crypto_core/salsa2012/ref"
#ifndef crypto_core_salsa2012_ref_VERSION
#define crypto_core_salsa2012_ref_VERSION "-"
#endif
#define crypto_core_salsa2012_VERSION crypto_core_salsa2012_ref_VERSION
#endif

View File

@ -0,0 +1,4 @@
#define CRYPTO_OUTPUTBYTES 64
#define CRYPTO_INPUTBYTES 16
#define CRYPTO_KEYBYTES 32
#define CRYPTO_CONSTBYTES 16

View File

@ -0,0 +1,134 @@
/*
version 20080913
D. J. Bernstein
Public domain.
*/
#include "crypto_core.h"
#define ROUNDS 12
typedef unsigned int uint32;
static uint32 rotate(uint32 u,int c)
{
return (u << c) | (u >> (32 - c));
}
static uint32 load_littleendian(const unsigned char *x)
{
return
(uint32) (x[0]) \
| (((uint32) (x[1])) << 8) \
| (((uint32) (x[2])) << 16) \
| (((uint32) (x[3])) << 24)
;
}
static void store_littleendian(unsigned char *x,uint32 u)
{
x[0] = u; u >>= 8;
x[1] = u; u >>= 8;
x[2] = u; u >>= 8;
x[3] = u;
}
int crypto_core(
unsigned char *out,
const unsigned char *in,
const unsigned char *k,
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;
int i;
j0 = x0 = load_littleendian(c + 0);
j1 = x1 = load_littleendian(k + 0);
j2 = x2 = load_littleendian(k + 4);
j3 = x3 = load_littleendian(k + 8);
j4 = x4 = load_littleendian(k + 12);
j5 = x5 = load_littleendian(c + 4);
j6 = x6 = load_littleendian(in + 0);
j7 = x7 = load_littleendian(in + 4);
j8 = x8 = load_littleendian(in + 8);
j9 = x9 = load_littleendian(in + 12);
j10 = x10 = load_littleendian(c + 8);
j11 = x11 = load_littleendian(k + 16);
j12 = x12 = load_littleendian(k + 20);
j13 = x13 = load_littleendian(k + 24);
j14 = x14 = load_littleendian(k + 28);
j15 = x15 = load_littleendian(c + 12);
for (i = ROUNDS;i > 0;i -= 2) {
x4 ^= rotate( x0+x12, 7);
x8 ^= rotate( x4+ x0, 9);
x12 ^= rotate( x8+ x4,13);
x0 ^= rotate(x12+ x8,18);
x9 ^= rotate( x5+ x1, 7);
x13 ^= rotate( x9+ x5, 9);
x1 ^= rotate(x13+ x9,13);
x5 ^= rotate( x1+x13,18);
x14 ^= rotate(x10+ x6, 7);
x2 ^= rotate(x14+x10, 9);
x6 ^= rotate( x2+x14,13);
x10 ^= rotate( x6+ x2,18);
x3 ^= rotate(x15+x11, 7);
x7 ^= rotate( x3+x15, 9);
x11 ^= rotate( x7+ x3,13);
x15 ^= rotate(x11+ x7,18);
x1 ^= rotate( x0+ x3, 7);
x2 ^= rotate( x1+ x0, 9);
x3 ^= rotate( x2+ x1,13);
x0 ^= rotate( x3+ x2,18);
x6 ^= rotate( x5+ x4, 7);
x7 ^= rotate( x6+ x5, 9);
x4 ^= rotate( x7+ x6,13);
x5 ^= rotate( x4+ x7,18);
x11 ^= rotate(x10+ x9, 7);
x8 ^= rotate(x11+x10, 9);
x9 ^= rotate( x8+x11,13);
x10 ^= rotate( x9+ x8,18);
x12 ^= rotate(x15+x14, 7);
x13 ^= rotate(x12+x15, 9);
x14 ^= rotate(x13+x12,13);
x15 ^= rotate(x14+x13,18);
}
x0 += j0;
x1 += j1;
x2 += j2;
x3 += j3;
x4 += j4;
x5 += j5;
x6 += j6;
x7 += j7;
x8 += j8;
x9 += j9;
x10 += j10;
x11 += j11;
x12 += j12;
x13 += j13;
x14 += j14;
x15 += j15;
store_littleendian(out + 0,x0);
store_littleendian(out + 4,x1);
store_littleendian(out + 8,x2);
store_littleendian(out + 12,x3);
store_littleendian(out + 16,x4);
store_littleendian(out + 20,x5);
store_littleendian(out + 24,x6);
store_littleendian(out + 28,x7);
store_littleendian(out + 32,x8);
store_littleendian(out + 36,x9);
store_littleendian(out + 40,x10);
store_littleendian(out + 44,x11);
store_littleendian(out + 48,x12);
store_littleendian(out + 52,x13);
store_littleendian(out + 56,x14);
store_littleendian(out + 60,x15);
return 0;
}

View File

@ -0,0 +1,20 @@
#ifndef crypto_core_H
#define crypto_core_H
#include "crypto_core_salsa2012.h"
#define crypto_core crypto_core_salsa2012
/* CHEESEBURGER crypto_core_salsa2012 */
#define crypto_core_OUTPUTBYTES crypto_core_salsa2012_OUTPUTBYTES
/* CHEESEBURGER crypto_core_salsa2012_OUTPUTBYTES */
#define crypto_core_INPUTBYTES crypto_core_salsa2012_INPUTBYTES
/* CHEESEBURGER crypto_core_salsa2012_INPUTBYTES */
#define crypto_core_KEYBYTES crypto_core_salsa2012_KEYBYTES
/* CHEESEBURGER crypto_core_salsa2012_KEYBYTES */
#define crypto_core_CONSTBYTES crypto_core_salsa2012_CONSTBYTES
/* CHEESEBURGER crypto_core_salsa2012_CONSTBYTES */
#define crypto_core_PRIMITIVE "salsa2012"
#define crypto_core_IMPLEMENTATION crypto_core_salsa2012_IMPLEMENTATION
#define crypto_core_VERSION crypto_core_salsa2012_VERSION
#endif

View File

@ -0,0 +1 @@
Daniel J. Bernstein

View File

@ -0,0 +1,33 @@
#ifndef crypto_core_salsa208_H
#define crypto_core_salsa208_H
#define crypto_core_salsa208_ref_OUTPUTBYTES 64
#define crypto_core_salsa208_ref_INPUTBYTES 16
#define crypto_core_salsa208_ref_KEYBYTES 32
#define crypto_core_salsa208_ref_CONSTBYTES 16
#ifdef __cplusplus
#include <string>
extern "C" {
#endif
extern int crypto_core_salsa208_ref(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_core_salsa208 crypto_core_salsa208_ref
/* POTATO crypto_core_salsa208_ref crypto_core_salsa208_ref crypto_core_salsa208 */
#define crypto_core_salsa208_OUTPUTBYTES crypto_core_salsa208_ref_OUTPUTBYTES
/* POTATO crypto_core_salsa208_ref_OUTPUTBYTES crypto_core_salsa208_ref crypto_core_salsa208 */
#define crypto_core_salsa208_INPUTBYTES crypto_core_salsa208_ref_INPUTBYTES
/* POTATO crypto_core_salsa208_ref_INPUTBYTES crypto_core_salsa208_ref crypto_core_salsa208 */
#define crypto_core_salsa208_KEYBYTES crypto_core_salsa208_ref_KEYBYTES
/* POTATO crypto_core_salsa208_ref_KEYBYTES crypto_core_salsa208_ref crypto_core_salsa208 */
#define crypto_core_salsa208_CONSTBYTES crypto_core_salsa208_ref_CONSTBYTES
/* POTATO crypto_core_salsa208_ref_CONSTBYTES crypto_core_salsa208_ref crypto_core_salsa208 */
#define crypto_core_salsa208_IMPLEMENTATION "crypto_core/salsa208/ref"
#ifndef crypto_core_salsa208_ref_VERSION
#define crypto_core_salsa208_ref_VERSION "-"
#endif
#define crypto_core_salsa208_VERSION crypto_core_salsa208_ref_VERSION
#endif

View File

@ -0,0 +1,4 @@
#define CRYPTO_OUTPUTBYTES 64
#define CRYPTO_INPUTBYTES 16
#define CRYPTO_KEYBYTES 32
#define CRYPTO_CONSTBYTES 16

View File

@ -0,0 +1,134 @@
/*
version 20080913
D. J. Bernstein
Public domain.
*/
#include "crypto_core.h"
#define ROUNDS 8
typedef unsigned int uint32;
static uint32 rotate(uint32 u,int c)
{
return (u << c) | (u >> (32 - c));
}
static uint32 load_littleendian(const unsigned char *x)
{
return
(uint32) (x[0]) \
| (((uint32) (x[1])) << 8) \
| (((uint32) (x[2])) << 16) \
| (((uint32) (x[3])) << 24)
;
}
static void store_littleendian(unsigned char *x,uint32 u)
{
x[0] = u; u >>= 8;
x[1] = u; u >>= 8;
x[2] = u; u >>= 8;
x[3] = u;
}
int crypto_core(
unsigned char *out,
const unsigned char *in,
const unsigned char *k,
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;
int i;
j0 = x0 = load_littleendian(c + 0);
j1 = x1 = load_littleendian(k + 0);
j2 = x2 = load_littleendian(k + 4);
j3 = x3 = load_littleendian(k + 8);
j4 = x4 = load_littleendian(k + 12);
j5 = x5 = load_littleendian(c + 4);
j6 = x6 = load_littleendian(in + 0);
j7 = x7 = load_littleendian(in + 4);
j8 = x8 = load_littleendian(in + 8);
j9 = x9 = load_littleendian(in + 12);
j10 = x10 = load_littleendian(c + 8);
j11 = x11 = load_littleendian(k + 16);
j12 = x12 = load_littleendian(k + 20);
j13 = x13 = load_littleendian(k + 24);
j14 = x14 = load_littleendian(k + 28);
j15 = x15 = load_littleendian(c + 12);
for (i = ROUNDS;i > 0;i -= 2) {
x4 ^= rotate( x0+x12, 7);
x8 ^= rotate( x4+ x0, 9);
x12 ^= rotate( x8+ x4,13);
x0 ^= rotate(x12+ x8,18);
x9 ^= rotate( x5+ x1, 7);
x13 ^= rotate( x9+ x5, 9);
x1 ^= rotate(x13+ x9,13);
x5 ^= rotate( x1+x13,18);
x14 ^= rotate(x10+ x6, 7);
x2 ^= rotate(x14+x10, 9);
x6 ^= rotate( x2+x14,13);
x10 ^= rotate( x6+ x2,18);
x3 ^= rotate(x15+x11, 7);
x7 ^= rotate( x3+x15, 9);
x11 ^= rotate( x7+ x3,13);
x15 ^= rotate(x11+ x7,18);
x1 ^= rotate( x0+ x3, 7);
x2 ^= rotate( x1+ x0, 9);
x3 ^= rotate( x2+ x1,13);
x0 ^= rotate( x3+ x2,18);
x6 ^= rotate( x5+ x4, 7);
x7 ^= rotate( x6+ x5, 9);
x4 ^= rotate( x7+ x6,13);
x5 ^= rotate( x4+ x7,18);
x11 ^= rotate(x10+ x9, 7);
x8 ^= rotate(x11+x10, 9);
x9 ^= rotate( x8+x11,13);
x10 ^= rotate( x9+ x8,18);
x12 ^= rotate(x15+x14, 7);
x13 ^= rotate(x12+x15, 9);
x14 ^= rotate(x13+x12,13);
x15 ^= rotate(x14+x13,18);
}
x0 += j0;
x1 += j1;
x2 += j2;
x3 += j3;
x4 += j4;
x5 += j5;
x6 += j6;
x7 += j7;
x8 += j8;
x9 += j9;
x10 += j10;
x11 += j11;
x12 += j12;
x13 += j13;
x14 += j14;
x15 += j15;
store_littleendian(out + 0,x0);
store_littleendian(out + 4,x1);
store_littleendian(out + 8,x2);
store_littleendian(out + 12,x3);
store_littleendian(out + 16,x4);
store_littleendian(out + 20,x5);
store_littleendian(out + 24,x6);
store_littleendian(out + 28,x7);
store_littleendian(out + 32,x8);
store_littleendian(out + 36,x9);
store_littleendian(out + 40,x10);
store_littleendian(out + 44,x11);
store_littleendian(out + 48,x12);
store_littleendian(out + 52,x13);
store_littleendian(out + 56,x14);
store_littleendian(out + 60,x15);
return 0;
}

View File

@ -0,0 +1,20 @@
#ifndef crypto_core_H
#define crypto_core_H
#include "crypto_core_salsa208.h"
#define crypto_core crypto_core_salsa208
/* CHEESEBURGER crypto_core_salsa208 */
#define crypto_core_OUTPUTBYTES crypto_core_salsa208_OUTPUTBYTES
/* CHEESEBURGER crypto_core_salsa208_OUTPUTBYTES */
#define crypto_core_INPUTBYTES crypto_core_salsa208_INPUTBYTES
/* CHEESEBURGER crypto_core_salsa208_INPUTBYTES */
#define crypto_core_KEYBYTES crypto_core_salsa208_KEYBYTES
/* CHEESEBURGER crypto_core_salsa208_KEYBYTES */
#define crypto_core_CONSTBYTES crypto_core_salsa208_CONSTBYTES
/* CHEESEBURGER crypto_core_salsa208_CONSTBYTES */
#define crypto_core_PRIMITIVE "salsa208"
#define crypto_core_IMPLEMENTATION crypto_core_salsa208_IMPLEMENTATION
#define crypto_core_VERSION crypto_core_salsa208_VERSION
#endif

View File

@ -0,0 +1 @@
Daniel J. Bernstein

View File

@ -0,0 +1,4 @@
#define CRYPTO_OUTPUTBYTES 64
#define CRYPTO_INPUTBYTES 16
#define CRYPTO_KEYBYTES 32
#define CRYPTO_CONSTBYTES 16

View File

@ -0,0 +1,134 @@
/*
version 20080912
D. J. Bernstein
Public domain.
*/
#include "crypto_core.h"
#define ROUNDS 20
typedef unsigned int uint32;
static uint32 rotate(uint32 u,int c)
{
return (u << c) | (u >> (32 - c));
}
static uint32 load_littleendian(const unsigned char *x)
{
return
(uint32) (x[0]) \
| (((uint32) (x[1])) << 8) \
| (((uint32) (x[2])) << 16) \
| (((uint32) (x[3])) << 24)
;
}
static void store_littleendian(unsigned char *x,uint32 u)
{
x[0] = u; u >>= 8;
x[1] = u; u >>= 8;
x[2] = u; u >>= 8;
x[3] = u;
}
int crypto_core(
unsigned char *out,
const unsigned char *in,
const unsigned char *k,
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;
int i;
j0 = x0 = load_littleendian(c + 0);
j1 = x1 = load_littleendian(k + 0);
j2 = x2 = load_littleendian(k + 4);
j3 = x3 = load_littleendian(k + 8);
j4 = x4 = load_littleendian(k + 12);
j5 = x5 = load_littleendian(c + 4);
j6 = x6 = load_littleendian(in + 0);
j7 = x7 = load_littleendian(in + 4);
j8 = x8 = load_littleendian(in + 8);
j9 = x9 = load_littleendian(in + 12);
j10 = x10 = load_littleendian(c + 8);
j11 = x11 = load_littleendian(k + 16);
j12 = x12 = load_littleendian(k + 20);
j13 = x13 = load_littleendian(k + 24);
j14 = x14 = load_littleendian(k + 28);
j15 = x15 = load_littleendian(c + 12);
for (i = ROUNDS;i > 0;i -= 2) {
x4 ^= rotate( x0+x12, 7);
x8 ^= rotate( x4+ x0, 9);
x12 ^= rotate( x8+ x4,13);
x0 ^= rotate(x12+ x8,18);
x9 ^= rotate( x5+ x1, 7);
x13 ^= rotate( x9+ x5, 9);
x1 ^= rotate(x13+ x9,13);
x5 ^= rotate( x1+x13,18);
x14 ^= rotate(x10+ x6, 7);
x2 ^= rotate(x14+x10, 9);
x6 ^= rotate( x2+x14,13);
x10 ^= rotate( x6+ x2,18);
x3 ^= rotate(x15+x11, 7);
x7 ^= rotate( x3+x15, 9);
x11 ^= rotate( x7+ x3,13);
x15 ^= rotate(x11+ x7,18);
x1 ^= rotate( x0+ x3, 7);
x2 ^= rotate( x1+ x0, 9);
x3 ^= rotate( x2+ x1,13);
x0 ^= rotate( x3+ x2,18);
x6 ^= rotate( x5+ x4, 7);
x7 ^= rotate( x6+ x5, 9);
x4 ^= rotate( x7+ x6,13);
x5 ^= rotate( x4+ x7,18);
x11 ^= rotate(x10+ x9, 7);
x8 ^= rotate(x11+x10, 9);
x9 ^= rotate( x8+x11,13);
x10 ^= rotate( x9+ x8,18);
x12 ^= rotate(x15+x14, 7);
x13 ^= rotate(x12+x15, 9);
x14 ^= rotate(x13+x12,13);
x15 ^= rotate(x14+x13,18);
}
x0 += j0;
x1 += j1;
x2 += j2;
x3 += j3;
x4 += j4;
x5 += j5;
x6 += j6;
x7 += j7;
x8 += j8;
x9 += j9;
x10 += j10;
x11 += j11;
x12 += j12;
x13 += j13;
x14 += j14;
x15 += j15;
store_littleendian(out + 0,x0);
store_littleendian(out + 4,x1);
store_littleendian(out + 8,x2);
store_littleendian(out + 12,x3);
store_littleendian(out + 16,x4);
store_littleendian(out + 20,x5);
store_littleendian(out + 24,x6);
store_littleendian(out + 28,x7);
store_littleendian(out + 32,x8);
store_littleendian(out + 36,x9);
store_littleendian(out + 40,x10);
store_littleendian(out + 44,x11);
store_littleendian(out + 48,x12);
store_littleendian(out + 52,x13);
store_littleendian(out + 56,x14);
store_littleendian(out + 60,x15);
return 0;
}

View File

@ -0,0 +1,20 @@
#ifndef crypto_core_H
#define crypto_core_H
#include "crypto_core_salsa20.h"
#define crypto_core crypto_core_salsa20
/* CHEESEBURGER crypto_core_salsa20 */
#define crypto_core_OUTPUTBYTES crypto_core_salsa20_OUTPUTBYTES
/* CHEESEBURGER crypto_core_salsa20_OUTPUTBYTES */
#define crypto_core_INPUTBYTES crypto_core_salsa20_INPUTBYTES
/* CHEESEBURGER crypto_core_salsa20_INPUTBYTES */
#define crypto_core_KEYBYTES crypto_core_salsa20_KEYBYTES
/* CHEESEBURGER crypto_core_salsa20_KEYBYTES */
#define crypto_core_CONSTBYTES crypto_core_salsa20_CONSTBYTES
/* CHEESEBURGER crypto_core_salsa20_CONSTBYTES */
#define crypto_core_PRIMITIVE "salsa20"
#define crypto_core_IMPLEMENTATION crypto_core_salsa20_IMPLEMENTATION
#define crypto_core_VERSION crypto_core_salsa20_VERSION
#endif

View File

@ -0,0 +1 @@
Daniel J. Bernstein

View File

@ -0,0 +1,25 @@
#ifndef crypto_hash_sha256_H
#define crypto_hash_sha256_H
#define crypto_hash_sha256_ref_BYTES 32
#ifdef __cplusplus
#include <string>
extern std::string crypto_hash_sha256_ref(const std::string &);
extern "C" {
#endif
extern int crypto_hash_sha256_ref(unsigned char *,const unsigned char *,unsigned long long);
#ifdef __cplusplus
}
#endif
#define crypto_hash_sha256 crypto_hash_sha256_ref
/* POTATO crypto_hash_sha256_ref crypto_hash_sha256_ref crypto_hash_sha256 */
#define crypto_hash_sha256_BYTES crypto_hash_sha256_ref_BYTES
/* POTATO crypto_hash_sha256_ref_BYTES crypto_hash_sha256_ref crypto_hash_sha256 */
#define crypto_hash_sha256_IMPLEMENTATION "crypto_hash/sha256/ref"
#ifndef crypto_hash_sha256_ref_VERSION
#define crypto_hash_sha256_ref_VERSION "-"
#endif
#define crypto_hash_sha256_VERSION crypto_hash_sha256_ref_VERSION
#endif

View File

@ -0,0 +1 @@
#define CRYPTO_BYTES 32

View File

@ -0,0 +1,14 @@
#ifndef crypto_hash_H
#define crypto_hash_H
#include "crypto_hash_sha256.h"
#define crypto_hash crypto_hash_sha256
/* CHEESEBURGER crypto_hash_sha256 */
#define crypto_hash_BYTES crypto_hash_sha256_BYTES
/* CHEESEBURGER crypto_hash_sha256_BYTES */
#define crypto_hash_PRIMITIVE "sha256"
#define crypto_hash_IMPLEMENTATION crypto_hash_sha256_IMPLEMENTATION
#define crypto_hash_VERSION crypto_hash_sha256_VERSION
#endif

View File

@ -0,0 +1,69 @@
/*
20080913
D. J. Bernstein
Public domain.
*/
#include "crypto_hashblocks_sha256.h"
#include "crypto_hash.h"
#define blocks crypto_hashblocks_sha256
typedef unsigned int uint32;
static const char iv[32] = {
0x6a,0x09,0xe6,0x67,
0xbb,0x67,0xae,0x85,
0x3c,0x6e,0xf3,0x72,
0xa5,0x4f,0xf5,0x3a,
0x51,0x0e,0x52,0x7f,
0x9b,0x05,0x68,0x8c,
0x1f,0x83,0xd9,0xab,
0x5b,0xe0,0xcd,0x19,
} ;
int crypto_hash(unsigned char *out,const unsigned char *in,unsigned long long inlen)
{
unsigned char h[32];
unsigned char padded[128];
int i;
unsigned long long bits = inlen << 3;
for (i = 0;i < 32;++i) h[i] = iv[i];
blocks(h,in,inlen);
in += inlen;
inlen &= 63;
in -= inlen;
for (i = 0;i < inlen;++i) padded[i] = in[i];
padded[inlen] = 0x80;
if (inlen < 56) {
for (i = inlen + 1;i < 56;++i) padded[i] = 0;
padded[56] = bits >> 56;
padded[57] = bits >> 48;
padded[58] = bits >> 40;
padded[59] = bits >> 32;
padded[60] = bits >> 24;
padded[61] = bits >> 16;
padded[62] = bits >> 8;
padded[63] = bits;
blocks(h,padded,64);
} else {
for (i = inlen + 1;i < 120;++i) padded[i] = 0;
padded[120] = bits >> 56;
padded[121] = bits >> 48;
padded[122] = bits >> 40;
padded[123] = bits >> 32;
padded[124] = bits >> 24;
padded[125] = bits >> 16;
padded[126] = bits >> 8;
padded[127] = bits;
blocks(h,padded,128);
}
for (i = 0;i < 32;++i) out[i] = h[i];
return 0;
}

View File

@ -0,0 +1 @@
Daniel J. Bernstein (wrapper around crypto_hashblocks/sha256)

View File

@ -0,0 +1,25 @@
#ifndef crypto_hash_sha512_H
#define crypto_hash_sha512_H
#define crypto_hash_sha512_ref_BYTES 64
#ifdef __cplusplus
#include <string>
extern std::string crypto_hash_sha512_ref(const std::string &);
extern "C" {
#endif
extern int crypto_hash_sha512_ref(unsigned char *,const unsigned char *,unsigned long long);
#ifdef __cplusplus
}
#endif
#define crypto_hash_sha512 crypto_hash_sha512_ref
/* POTATO crypto_hash_sha512_ref crypto_hash_sha512_ref crypto_hash_sha512 */
#define crypto_hash_sha512_BYTES crypto_hash_sha512_ref_BYTES
/* POTATO crypto_hash_sha512_ref_BYTES crypto_hash_sha512_ref crypto_hash_sha512 */
#define crypto_hash_sha512_IMPLEMENTATION "crypto_hash/sha512/ref"
#ifndef crypto_hash_sha512_ref_VERSION
#define crypto_hash_sha512_ref_VERSION "-"
#endif
#define crypto_hash_sha512_VERSION crypto_hash_sha512_ref_VERSION
#endif

View File

@ -0,0 +1 @@
#define CRYPTO_BYTES 64

View File

@ -0,0 +1,14 @@
#ifndef crypto_hash_H
#define crypto_hash_H
#include "crypto_hash_sha512.h"
#define crypto_hash crypto_hash_sha512
/* CHEESEBURGER crypto_hash_sha512 */
#define crypto_hash_BYTES crypto_hash_sha512_BYTES
/* CHEESEBURGER crypto_hash_sha512_BYTES */
#define crypto_hash_PRIMITIVE "sha512"
#define crypto_hash_IMPLEMENTATION crypto_hash_sha512_IMPLEMENTATION
#define crypto_hash_VERSION crypto_hash_sha512_VERSION
#endif

View File

@ -0,0 +1,71 @@
/*
20080913
D. J. Bernstein
Public domain.
*/
#include "crypto_hashblocks_sha512.h"
#include "crypto_hash.h"
#define blocks crypto_hashblocks_sha512
static const unsigned char iv[64] = {
0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08,
0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b,
0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b,
0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1,
0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1,
0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f,
0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b,
0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79
} ;
typedef unsigned long long uint64;
int crypto_hash(unsigned char *out,const unsigned char *in,unsigned long long inlen)
{
unsigned char h[64];
unsigned char padded[256];
int i;
unsigned long long bytes = inlen;
for (i = 0;i < 64;++i) h[i] = iv[i];
blocks(h,in,inlen);
in += inlen;
inlen &= 127;
in -= inlen;
for (i = 0;i < inlen;++i) padded[i] = in[i];
padded[inlen] = 0x80;
if (inlen < 112) {
for (i = inlen + 1;i < 119;++i) padded[i] = 0;
padded[119] = bytes >> 61;
padded[120] = bytes >> 53;
padded[121] = bytes >> 45;
padded[122] = bytes >> 37;
padded[123] = bytes >> 29;
padded[124] = bytes >> 21;
padded[125] = bytes >> 13;
padded[126] = bytes >> 5;
padded[127] = bytes << 3;
blocks(h,padded,128);
} else {
for (i = inlen + 1;i < 247;++i) padded[i] = 0;
padded[247] = bytes >> 61;
padded[248] = bytes >> 53;
padded[249] = bytes >> 45;
padded[250] = bytes >> 37;
padded[251] = bytes >> 29;
padded[252] = bytes >> 21;
padded[253] = bytes >> 13;
padded[254] = bytes >> 5;
padded[255] = bytes << 3;
blocks(h,padded,256);
}
for (i = 0;i < 64;++i) out[i] = h[i];
return 0;
}

View File

@ -0,0 +1 @@
Daniel J. Bernstein (wrapper around crypto_hashblocks/sha512)

View File

@ -0,0 +1,27 @@
#ifndef crypto_hashblocks_sha256_H
#define crypto_hashblocks_sha256_H
#define crypto_hashblocks_sha256_ref_STATEBYTES 32
#define crypto_hashblocks_sha256_ref_BLOCKBYTES 64
#ifdef __cplusplus
#include <string>
extern "C" {
#endif
extern int crypto_hashblocks_sha256_ref(unsigned char *,const unsigned char *,unsigned long long);
#ifdef __cplusplus
}
#endif
#define crypto_hashblocks_sha256 crypto_hashblocks_sha256_ref
/* POTATO crypto_hashblocks_sha256_ref crypto_hashblocks_sha256_ref crypto_hashblocks_sha256 */
#define crypto_hashblocks_sha256_STATEBYTES crypto_hashblocks_sha256_ref_STATEBYTES
/* POTATO crypto_hashblocks_sha256_ref_STATEBYTES crypto_hashblocks_sha256_ref crypto_hashblocks_sha256 */
#define crypto_hashblocks_sha256_BLOCKBYTES crypto_hashblocks_sha256_ref_BLOCKBYTES
/* POTATO crypto_hashblocks_sha256_ref_BLOCKBYTES crypto_hashblocks_sha256_ref crypto_hashblocks_sha256 */
#define crypto_hashblocks_sha256_IMPLEMENTATION "crypto_hashblocks/sha256/ref"
#ifndef crypto_hashblocks_sha256_ref_VERSION
#define crypto_hashblocks_sha256_ref_VERSION "-"
#endif
#define crypto_hashblocks_sha256_VERSION crypto_hashblocks_sha256_ref_VERSION
#endif

View File

@ -0,0 +1,2 @@
#define CRYPTO_STATEBYTES 32
#define CRYPTO_BLOCKBYTES 64

View File

@ -0,0 +1,212 @@
#include "crypto_hashblocks.h"
typedef unsigned int uint32;
static uint32 load_bigendian(const unsigned char *x)
{
return
(uint32) (x[3]) \
| (((uint32) (x[2])) << 8) \
| (((uint32) (x[1])) << 16) \
| (((uint32) (x[0])) << 24)
;
}
static void store_bigendian(unsigned char *x,uint32 u)
{
x[3] = u; u >>= 8;
x[2] = u; u >>= 8;
x[1] = u; u >>= 8;
x[0] = u;
}
#define SHR(x,c) ((x) >> (c))
#define ROTR(x,c) (((x) >> (c)) | ((x) << (32 - (c))))
#define Ch(x,y,z) ((x & y) ^ (~x & z))
#define Maj(x,y,z) ((x & y) ^ (x & z) ^ (y & z))
#define Sigma0(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
#define Sigma1(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
#define sigma0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
#define sigma1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
#define M(w0,w14,w9,w1) w0 = sigma1(w14) + w9 + sigma0(w1) + w0;
#define EXPAND \
M(w0 ,w14,w9 ,w1 ) \
M(w1 ,w15,w10,w2 ) \
M(w2 ,w0 ,w11,w3 ) \
M(w3 ,w1 ,w12,w4 ) \
M(w4 ,w2 ,w13,w5 ) \
M(w5 ,w3 ,w14,w6 ) \
M(w6 ,w4 ,w15,w7 ) \
M(w7 ,w5 ,w0 ,w8 ) \
M(w8 ,w6 ,w1 ,w9 ) \
M(w9 ,w7 ,w2 ,w10) \
M(w10,w8 ,w3 ,w11) \
M(w11,w9 ,w4 ,w12) \
M(w12,w10,w5 ,w13) \
M(w13,w11,w6 ,w14) \
M(w14,w12,w7 ,w15) \
M(w15,w13,w8 ,w0 )
#define F(w,k) \
T1 = h + Sigma1(e) + Ch(e,f,g) + k + w; \
T2 = Sigma0(a) + Maj(a,b,c); \
h = g; \
g = f; \
f = e; \
e = d + T1; \
d = c; \
c = b; \
b = a; \
a = T1 + T2;
int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned long long inlen)
{
uint32 state[8];
uint32 a;
uint32 b;
uint32 c;
uint32 d;
uint32 e;
uint32 f;
uint32 g;
uint32 h;
uint32 T1;
uint32 T2;
a = load_bigendian(statebytes + 0); state[0] = a;
b = load_bigendian(statebytes + 4); state[1] = b;
c = load_bigendian(statebytes + 8); state[2] = c;
d = load_bigendian(statebytes + 12); state[3] = d;
e = load_bigendian(statebytes + 16); state[4] = e;
f = load_bigendian(statebytes + 20); state[5] = f;
g = load_bigendian(statebytes + 24); state[6] = g;
h = load_bigendian(statebytes + 28); state[7] = h;
while (inlen >= 64) {
uint32 w0 = load_bigendian(in + 0);
uint32 w1 = load_bigendian(in + 4);
uint32 w2 = load_bigendian(in + 8);
uint32 w3 = load_bigendian(in + 12);
uint32 w4 = load_bigendian(in + 16);
uint32 w5 = load_bigendian(in + 20);
uint32 w6 = load_bigendian(in + 24);
uint32 w7 = load_bigendian(in + 28);
uint32 w8 = load_bigendian(in + 32);
uint32 w9 = load_bigendian(in + 36);
uint32 w10 = load_bigendian(in + 40);
uint32 w11 = load_bigendian(in + 44);
uint32 w12 = load_bigendian(in + 48);
uint32 w13 = load_bigendian(in + 52);
uint32 w14 = load_bigendian(in + 56);
uint32 w15 = load_bigendian(in + 60);
F(w0 ,0x428a2f98)
F(w1 ,0x71374491)
F(w2 ,0xb5c0fbcf)
F(w3 ,0xe9b5dba5)
F(w4 ,0x3956c25b)
F(w5 ,0x59f111f1)
F(w6 ,0x923f82a4)
F(w7 ,0xab1c5ed5)
F(w8 ,0xd807aa98)
F(w9 ,0x12835b01)
F(w10,0x243185be)
F(w11,0x550c7dc3)
F(w12,0x72be5d74)
F(w13,0x80deb1fe)
F(w14,0x9bdc06a7)
F(w15,0xc19bf174)
EXPAND
F(w0 ,0xe49b69c1)
F(w1 ,0xefbe4786)
F(w2 ,0x0fc19dc6)
F(w3 ,0x240ca1cc)
F(w4 ,0x2de92c6f)
F(w5 ,0x4a7484aa)
F(w6 ,0x5cb0a9dc)
F(w7 ,0x76f988da)
F(w8 ,0x983e5152)
F(w9 ,0xa831c66d)
F(w10,0xb00327c8)
F(w11,0xbf597fc7)
F(w12,0xc6e00bf3)
F(w13,0xd5a79147)
F(w14,0x06ca6351)
F(w15,0x14292967)
EXPAND
F(w0 ,0x27b70a85)
F(w1 ,0x2e1b2138)
F(w2 ,0x4d2c6dfc)
F(w3 ,0x53380d13)
F(w4 ,0x650a7354)
F(w5 ,0x766a0abb)
F(w6 ,0x81c2c92e)
F(w7 ,0x92722c85)
F(w8 ,0xa2bfe8a1)
F(w9 ,0xa81a664b)
F(w10,0xc24b8b70)
F(w11,0xc76c51a3)
F(w12,0xd192e819)
F(w13,0xd6990624)
F(w14,0xf40e3585)
F(w15,0x106aa070)
EXPAND
F(w0 ,0x19a4c116)
F(w1 ,0x1e376c08)
F(w2 ,0x2748774c)
F(w3 ,0x34b0bcb5)
F(w4 ,0x391c0cb3)
F(w5 ,0x4ed8aa4a)
F(w6 ,0x5b9cca4f)
F(w7 ,0x682e6ff3)
F(w8 ,0x748f82ee)
F(w9 ,0x78a5636f)
F(w10,0x84c87814)
F(w11,0x8cc70208)
F(w12,0x90befffa)
F(w13,0xa4506ceb)
F(w14,0xbef9a3f7)
F(w15,0xc67178f2)
a += state[0];
b += state[1];
c += state[2];
d += state[3];
e += state[4];
f += state[5];
g += state[6];
h += state[7];
state[0] = a;
state[1] = b;
state[2] = c;
state[3] = d;
state[4] = e;
state[5] = f;
state[6] = g;
state[7] = h;
in += 64;
inlen -= 64;
}
store_bigendian(statebytes + 0,state[0]);
store_bigendian(statebytes + 4,state[1]);
store_bigendian(statebytes + 8,state[2]);
store_bigendian(statebytes + 12,state[3]);
store_bigendian(statebytes + 16,state[4]);
store_bigendian(statebytes + 20,state[5]);
store_bigendian(statebytes + 24,state[6]);
store_bigendian(statebytes + 28,state[7]);
return 0;
}

View File

@ -0,0 +1,16 @@
#ifndef crypto_hashblocks_H
#define crypto_hashblocks_H
#include "crypto_hashblocks_sha256.h"
#define crypto_hashblocks crypto_hashblocks_sha256
/* CHEESEBURGER crypto_hashblocks_sha256 */
#define crypto_hashblocks_STATEBYTES crypto_hashblocks_sha256_STATEBYTES
/* CHEESEBURGER crypto_hashblocks_sha256_STATEBYTES */
#define crypto_hashblocks_BLOCKBYTES crypto_hashblocks_sha256_BLOCKBYTES
/* CHEESEBURGER crypto_hashblocks_sha256_BLOCKBYTES */
#define crypto_hashblocks_PRIMITIVE "sha256"
#define crypto_hashblocks_IMPLEMENTATION crypto_hashblocks_sha256_IMPLEMENTATION
#define crypto_hashblocks_VERSION crypto_hashblocks_sha256_VERSION
#endif

View File

@ -0,0 +1 @@
Daniel J. Bernstein

View File

@ -0,0 +1,27 @@
#ifndef crypto_hashblocks_sha512_H
#define crypto_hashblocks_sha512_H
#define crypto_hashblocks_sha512_ref_STATEBYTES 64
#define crypto_hashblocks_sha512_ref_BLOCKBYTES 128
#ifdef __cplusplus
#include <string>
extern "C" {
#endif
extern int crypto_hashblocks_sha512_ref(unsigned char *,const unsigned char *,unsigned long long);
#ifdef __cplusplus
}
#endif
#define crypto_hashblocks_sha512 crypto_hashblocks_sha512_ref
/* POTATO crypto_hashblocks_sha512_ref crypto_hashblocks_sha512_ref crypto_hashblocks_sha512 */
#define crypto_hashblocks_sha512_STATEBYTES crypto_hashblocks_sha512_ref_STATEBYTES
/* POTATO crypto_hashblocks_sha512_ref_STATEBYTES crypto_hashblocks_sha512_ref crypto_hashblocks_sha512 */
#define crypto_hashblocks_sha512_BLOCKBYTES crypto_hashblocks_sha512_ref_BLOCKBYTES
/* POTATO crypto_hashblocks_sha512_ref_BLOCKBYTES crypto_hashblocks_sha512_ref crypto_hashblocks_sha512 */
#define crypto_hashblocks_sha512_IMPLEMENTATION "crypto_hashblocks/sha512/ref"
#ifndef crypto_hashblocks_sha512_ref_VERSION
#define crypto_hashblocks_sha512_ref_VERSION "-"
#endif
#define crypto_hashblocks_sha512_VERSION crypto_hashblocks_sha512_ref_VERSION
#endif

View File

@ -0,0 +1,2 @@
#define CRYPTO_STATEBYTES 64
#define CRYPTO_BLOCKBYTES 128

View File

@ -0,0 +1,239 @@
#include "crypto_hashblocks.h"
typedef unsigned long long uint64;
static uint64 load_bigendian(const unsigned char *x)
{
return
(uint64) (x[7]) \
| (((uint64) (x[6])) << 8) \
| (((uint64) (x[5])) << 16) \
| (((uint64) (x[4])) << 24) \
| (((uint64) (x[3])) << 32) \
| (((uint64) (x[2])) << 40) \
| (((uint64) (x[1])) << 48) \
| (((uint64) (x[0])) << 56)
;
}
static void store_bigendian(unsigned char *x,uint64 u)
{
x[7] = u; u >>= 8;
x[6] = u; u >>= 8;
x[5] = u; u >>= 8;
x[4] = u; u >>= 8;
x[3] = u; u >>= 8;
x[2] = u; u >>= 8;
x[1] = u; u >>= 8;
x[0] = u;
}
#define SHR(x,c) ((x) >> (c))
#define ROTR(x,c) (((x) >> (c)) | ((x) << (64 - (c))))
#define Ch(x,y,z) ((x & y) ^ (~x & z))
#define Maj(x,y,z) ((x & y) ^ (x & z) ^ (y & z))
#define Sigma0(x) (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39))
#define Sigma1(x) (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41))
#define sigma0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x,7))
#define sigma1(x) (ROTR(x,19) ^ ROTR(x,61) ^ SHR(x,6))
#define M(w0,w14,w9,w1) w0 = sigma1(w14) + w9 + sigma0(w1) + w0;
#define EXPAND \
M(w0 ,w14,w9 ,w1 ) \
M(w1 ,w15,w10,w2 ) \
M(w2 ,w0 ,w11,w3 ) \
M(w3 ,w1 ,w12,w4 ) \
M(w4 ,w2 ,w13,w5 ) \
M(w5 ,w3 ,w14,w6 ) \
M(w6 ,w4 ,w15,w7 ) \
M(w7 ,w5 ,w0 ,w8 ) \
M(w8 ,w6 ,w1 ,w9 ) \
M(w9 ,w7 ,w2 ,w10) \
M(w10,w8 ,w3 ,w11) \
M(w11,w9 ,w4 ,w12) \
M(w12,w10,w5 ,w13) \
M(w13,w11,w6 ,w14) \
M(w14,w12,w7 ,w15) \
M(w15,w13,w8 ,w0 )
#define F(w,k) \
T1 = h + Sigma1(e) + Ch(e,f,g) + k + w; \
T2 = Sigma0(a) + Maj(a,b,c); \
h = g; \
g = f; \
f = e; \
e = d + T1; \
d = c; \
c = b; \
b = a; \
a = T1 + T2;
int crypto_hashblocks(unsigned char *statebytes,const unsigned char *in,unsigned long long inlen)
{
uint64 state[8];
uint64 a;
uint64 b;
uint64 c;
uint64 d;
uint64 e;
uint64 f;
uint64 g;
uint64 h;
uint64 T1;
uint64 T2;
a = load_bigendian(statebytes + 0); state[0] = a;
b = load_bigendian(statebytes + 8); state[1] = b;
c = load_bigendian(statebytes + 16); state[2] = c;
d = load_bigendian(statebytes + 24); state[3] = d;
e = load_bigendian(statebytes + 32); state[4] = e;
f = load_bigendian(statebytes + 40); state[5] = f;
g = load_bigendian(statebytes + 48); state[6] = g;
h = load_bigendian(statebytes + 56); state[7] = h;
while (inlen >= 128) {
uint64 w0 = load_bigendian(in + 0);
uint64 w1 = load_bigendian(in + 8);
uint64 w2 = load_bigendian(in + 16);
uint64 w3 = load_bigendian(in + 24);
uint64 w4 = load_bigendian(in + 32);
uint64 w5 = load_bigendian(in + 40);
uint64 w6 = load_bigendian(in + 48);
uint64 w7 = load_bigendian(in + 56);
uint64 w8 = load_bigendian(in + 64);
uint64 w9 = load_bigendian(in + 72);
uint64 w10 = load_bigendian(in + 80);
uint64 w11 = load_bigendian(in + 88);
uint64 w12 = load_bigendian(in + 96);
uint64 w13 = load_bigendian(in + 104);
uint64 w14 = load_bigendian(in + 112);
uint64 w15 = load_bigendian(in + 120);
F(w0 ,0x428a2f98d728ae22ULL)
F(w1 ,0x7137449123ef65cdULL)
F(w2 ,0xb5c0fbcfec4d3b2fULL)
F(w3 ,0xe9b5dba58189dbbcULL)
F(w4 ,0x3956c25bf348b538ULL)
F(w5 ,0x59f111f1b605d019ULL)
F(w6 ,0x923f82a4af194f9bULL)
F(w7 ,0xab1c5ed5da6d8118ULL)
F(w8 ,0xd807aa98a3030242ULL)
F(w9 ,0x12835b0145706fbeULL)
F(w10,0x243185be4ee4b28cULL)
F(w11,0x550c7dc3d5ffb4e2ULL)
F(w12,0x72be5d74f27b896fULL)
F(w13,0x80deb1fe3b1696b1ULL)
F(w14,0x9bdc06a725c71235ULL)
F(w15,0xc19bf174cf692694ULL)
EXPAND
F(w0 ,0xe49b69c19ef14ad2ULL)
F(w1 ,0xefbe4786384f25e3ULL)
F(w2 ,0x0fc19dc68b8cd5b5ULL)
F(w3 ,0x240ca1cc77ac9c65ULL)
F(w4 ,0x2de92c6f592b0275ULL)
F(w5 ,0x4a7484aa6ea6e483ULL)
F(w6 ,0x5cb0a9dcbd41fbd4ULL)
F(w7 ,0x76f988da831153b5ULL)
F(w8 ,0x983e5152ee66dfabULL)
F(w9 ,0xa831c66d2db43210ULL)
F(w10,0xb00327c898fb213fULL)
F(w11,0xbf597fc7beef0ee4ULL)
F(w12,0xc6e00bf33da88fc2ULL)
F(w13,0xd5a79147930aa725ULL)
F(w14,0x06ca6351e003826fULL)
F(w15,0x142929670a0e6e70ULL)
EXPAND
F(w0 ,0x27b70a8546d22ffcULL)
F(w1 ,0x2e1b21385c26c926ULL)
F(w2 ,0x4d2c6dfc5ac42aedULL)
F(w3 ,0x53380d139d95b3dfULL)
F(w4 ,0x650a73548baf63deULL)
F(w5 ,0x766a0abb3c77b2a8ULL)
F(w6 ,0x81c2c92e47edaee6ULL)
F(w7 ,0x92722c851482353bULL)
F(w8 ,0xa2bfe8a14cf10364ULL)
F(w9 ,0xa81a664bbc423001ULL)
F(w10,0xc24b8b70d0f89791ULL)
F(w11,0xc76c51a30654be30ULL)
F(w12,0xd192e819d6ef5218ULL)
F(w13,0xd69906245565a910ULL)
F(w14,0xf40e35855771202aULL)
F(w15,0x106aa07032bbd1b8ULL)
EXPAND
F(w0 ,0x19a4c116b8d2d0c8ULL)
F(w1 ,0x1e376c085141ab53ULL)
F(w2 ,0x2748774cdf8eeb99ULL)
F(w3 ,0x34b0bcb5e19b48a8ULL)
F(w4 ,0x391c0cb3c5c95a63ULL)
F(w5 ,0x4ed8aa4ae3418acbULL)
F(w6 ,0x5b9cca4f7763e373ULL)
F(w7 ,0x682e6ff3d6b2b8a3ULL)
F(w8 ,0x748f82ee5defb2fcULL)
F(w9 ,0x78a5636f43172f60ULL)
F(w10,0x84c87814a1f0ab72ULL)
F(w11,0x8cc702081a6439ecULL)
F(w12,0x90befffa23631e28ULL)
F(w13,0xa4506cebde82bde9ULL)
F(w14,0xbef9a3f7b2c67915ULL)
F(w15,0xc67178f2e372532bULL)
EXPAND
F(w0 ,0xca273eceea26619cULL)
F(w1 ,0xd186b8c721c0c207ULL)
F(w2 ,0xeada7dd6cde0eb1eULL)
F(w3 ,0xf57d4f7fee6ed178ULL)
F(w4 ,0x06f067aa72176fbaULL)
F(w5 ,0x0a637dc5a2c898a6ULL)
F(w6 ,0x113f9804bef90daeULL)
F(w7 ,0x1b710b35131c471bULL)
F(w8 ,0x28db77f523047d84ULL)
F(w9 ,0x32caab7b40c72493ULL)
F(w10,0x3c9ebe0a15c9bebcULL)
F(w11,0x431d67c49c100d4cULL)
F(w12,0x4cc5d4becb3e42b6ULL)
F(w13,0x597f299cfc657e2aULL)
F(w14,0x5fcb6fab3ad6faecULL)
F(w15,0x6c44198c4a475817ULL)
a += state[0];
b += state[1];
c += state[2];
d += state[3];
e += state[4];
f += state[5];
g += state[6];
h += state[7];
state[0] = a;
state[1] = b;
state[2] = c;
state[3] = d;
state[4] = e;
state[5] = f;
state[6] = g;
state[7] = h;
in += 128;
inlen -= 128;
}
store_bigendian(statebytes + 0,state[0]);
store_bigendian(statebytes + 8,state[1]);
store_bigendian(statebytes + 16,state[2]);
store_bigendian(statebytes + 24,state[3]);
store_bigendian(statebytes + 32,state[4]);
store_bigendian(statebytes + 40,state[5]);
store_bigendian(statebytes + 48,state[6]);
store_bigendian(statebytes + 56,state[7]);
return 0;
}

View File

@ -0,0 +1,16 @@
#ifndef crypto_hashblocks_H
#define crypto_hashblocks_H
#include "crypto_hashblocks_sha512.h"
#define crypto_hashblocks crypto_hashblocks_sha512
/* CHEESEBURGER crypto_hashblocks_sha512 */
#define crypto_hashblocks_STATEBYTES crypto_hashblocks_sha512_STATEBYTES
/* CHEESEBURGER crypto_hashblocks_sha512_STATEBYTES */
#define crypto_hashblocks_BLOCKBYTES crypto_hashblocks_sha512_BLOCKBYTES
/* CHEESEBURGER crypto_hashblocks_sha512_BLOCKBYTES */
#define crypto_hashblocks_PRIMITIVE "sha512"
#define crypto_hashblocks_IMPLEMENTATION crypto_hashblocks_sha512_IMPLEMENTATION
#define crypto_hashblocks_VERSION crypto_hashblocks_sha512_VERSION
#endif

View File

@ -0,0 +1 @@
Daniel J. Bernstein

View File

@ -0,0 +1,32 @@
#ifndef crypto_onetimeauth_poly1305_H
#define crypto_onetimeauth_poly1305_H
#define crypto_onetimeauth_poly1305_ref_BYTES 16
#define crypto_onetimeauth_poly1305_ref_KEYBYTES 32
#ifdef __cplusplus
#include <string>
extern std::string crypto_onetimeauth_poly1305_ref(const std::string &,const std::string &);
extern void crypto_onetimeauth_poly1305_ref_verify(const std::string &,const std::string &,const std::string &);
extern "C" {
#endif
extern int crypto_onetimeauth_poly1305_ref(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_onetimeauth_poly1305_ref_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_onetimeauth_poly1305 crypto_onetimeauth_poly1305_ref
/* POTATO crypto_onetimeauth_poly1305_ref crypto_onetimeauth_poly1305_ref crypto_onetimeauth_poly1305 */
#define crypto_onetimeauth_poly1305_verify crypto_onetimeauth_poly1305_ref_verify
/* POTATO crypto_onetimeauth_poly1305_ref_verify crypto_onetimeauth_poly1305_ref crypto_onetimeauth_poly1305 */
#define crypto_onetimeauth_poly1305_BYTES crypto_onetimeauth_poly1305_ref_BYTES
/* POTATO crypto_onetimeauth_poly1305_ref_BYTES crypto_onetimeauth_poly1305_ref crypto_onetimeauth_poly1305 */
#define crypto_onetimeauth_poly1305_KEYBYTES crypto_onetimeauth_poly1305_ref_KEYBYTES
/* POTATO crypto_onetimeauth_poly1305_ref_KEYBYTES crypto_onetimeauth_poly1305_ref crypto_onetimeauth_poly1305 */
#define crypto_onetimeauth_poly1305_IMPLEMENTATION "crypto_onetimeauth/poly1305/ref"
#ifndef crypto_onetimeauth_poly1305_ref_VERSION
#define crypto_onetimeauth_poly1305_ref_VERSION "-"
#endif
#define crypto_onetimeauth_poly1305_VERSION crypto_onetimeauth_poly1305_ref_VERSION
#endif

View File

@ -0,0 +1,2 @@
#define CRYPTO_BYTES 16
#define CRYPTO_KEYBYTES 32

View File

@ -0,0 +1,104 @@
/*
20080912
D. J. Bernstein
Public domain.
*/
#include "crypto_onetimeauth.h"
static void add(unsigned int h[17],const unsigned int c[17])
{
unsigned int j;
unsigned int u;
u = 0;
for (j = 0;j < 17;++j) { u += h[j] + c[j]; h[j] = u & 255; u >>= 8; }
}
static void squeeze(unsigned int h[17])
{
unsigned int j;
unsigned int u;
u = 0;
for (j = 0;j < 16;++j) { u += h[j]; h[j] = u & 255; u >>= 8; }
u += h[16]; h[16] = u & 3;
u = 5 * (u >> 2);
for (j = 0;j < 16;++j) { u += h[j]; h[j] = u & 255; u >>= 8; }
u += h[16]; h[16] = u;
}
static const unsigned int minusp[17] = {
5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252
} ;
static void freeze(unsigned int h[17])
{
unsigned int horig[17];
unsigned int j;
unsigned int negative;
for (j = 0;j < 17;++j) horig[j] = h[j];
add(h,minusp);
negative = -(h[16] >> 7);
for (j = 0;j < 17;++j) h[j] ^= negative & (horig[j] ^ h[j]);
}
static void mulmod(unsigned int h[17],const unsigned int r[17])
{
unsigned int hr[17];
unsigned int i;
unsigned int j;
unsigned int u;
for (i = 0;i < 17;++i) {
u = 0;
for (j = 0;j <= i;++j) u += h[j] * r[i - j];
for (j = i + 1;j < 17;++j) u += 320 * h[j] * r[i + 17 - j];
hr[i] = u;
}
for (i = 0;i < 17;++i) h[i] = hr[i];
squeeze(h);
}
int crypto_onetimeauth(unsigned char *out,const unsigned char *in,unsigned long long inlen,const unsigned char *k)
{
unsigned int j;
unsigned int r[17];
unsigned int h[17];
unsigned int c[17];
r[0] = k[0];
r[1] = k[1];
r[2] = k[2];
r[3] = k[3] & 15;
r[4] = k[4] & 252;
r[5] = k[5];
r[6] = k[6];
r[7] = k[7] & 15;
r[8] = k[8] & 252;
r[9] = k[9];
r[10] = k[10];
r[11] = k[11] & 15;
r[12] = k[12] & 252;
r[13] = k[13];
r[14] = k[14];
r[15] = k[15] & 15;
r[16] = 0;
for (j = 0;j < 17;++j) h[j] = 0;
while (inlen > 0) {
for (j = 0;j < 17;++j) c[j] = 0;
for (j = 0;(j < 16) && (j < inlen);++j) c[j] = in[j];
c[j] = 1;
in += j; inlen -= j;
add(h,c);
mulmod(h,r);
}
freeze(h);
for (j = 0;j < 16;++j) c[j] = k[j + 16];
c[16] = 0;
add(h,c);
for (j = 0;j < 16;++j) out[j] = h[j];
return 0;
}

View File

@ -0,0 +1,18 @@
#ifndef crypto_onetimeauth_H
#define crypto_onetimeauth_H
#include "crypto_onetimeauth_poly1305.h"
#define crypto_onetimeauth crypto_onetimeauth_poly1305
/* CHEESEBURGER crypto_onetimeauth_poly1305 */
#define crypto_onetimeauth_verify crypto_onetimeauth_poly1305_verify
/* CHEESEBURGER crypto_onetimeauth_poly1305_verify */
#define crypto_onetimeauth_BYTES crypto_onetimeauth_poly1305_BYTES
/* CHEESEBURGER crypto_onetimeauth_poly1305_BYTES */
#define crypto_onetimeauth_KEYBYTES crypto_onetimeauth_poly1305_KEYBYTES
/* CHEESEBURGER crypto_onetimeauth_poly1305_KEYBYTES */
#define crypto_onetimeauth_PRIMITIVE "poly1305"
#define crypto_onetimeauth_IMPLEMENTATION crypto_onetimeauth_poly1305_IMPLEMENTATION
#define crypto_onetimeauth_VERSION crypto_onetimeauth_poly1305_VERSION
#endif

View File

@ -0,0 +1,9 @@
#include "crypto_verify_16.h"
#include "crypto_onetimeauth.h"
int crypto_onetimeauth_verify(const unsigned char *h,const unsigned char *in,unsigned long long inlen,const unsigned char *k)
{
unsigned char correct[16];
crypto_onetimeauth(correct,in,inlen,k);
return crypto_verify_16(h,correct);
}

View File

@ -0,0 +1,32 @@
#ifndef crypto_scalarmult_curve25519_H
#define crypto_scalarmult_curve25519_H
#define crypto_scalarmult_curve25519_ref_BYTES 32
#define crypto_scalarmult_curve25519_ref_SCALARBYTES 32
#ifdef __cplusplus
#include <string>
extern std::string crypto_scalarmult_curve25519_ref(const std::string &,const std::string &);
extern std::string crypto_scalarmult_curve25519_ref_base(const std::string &);
extern "C" {
#endif
extern int crypto_scalarmult_curve25519_ref(unsigned char *,const unsigned char *,const unsigned char *);
extern int crypto_scalarmult_curve25519_ref_base(unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_scalarmult_curve25519 crypto_scalarmult_curve25519_ref
/* POTATO crypto_scalarmult_curve25519_ref crypto_scalarmult_curve25519_ref crypto_scalarmult_curve25519 */
#define crypto_scalarmult_curve25519_base crypto_scalarmult_curve25519_ref_base
/* POTATO crypto_scalarmult_curve25519_ref_base crypto_scalarmult_curve25519_ref crypto_scalarmult_curve25519 */
#define crypto_scalarmult_curve25519_BYTES crypto_scalarmult_curve25519_ref_BYTES
/* POTATO crypto_scalarmult_curve25519_ref_BYTES crypto_scalarmult_curve25519_ref crypto_scalarmult_curve25519 */
#define crypto_scalarmult_curve25519_SCALARBYTES crypto_scalarmult_curve25519_ref_SCALARBYTES
/* POTATO crypto_scalarmult_curve25519_ref_SCALARBYTES crypto_scalarmult_curve25519_ref crypto_scalarmult_curve25519 */
#define crypto_scalarmult_curve25519_IMPLEMENTATION "crypto_scalarmult/curve25519/ref"
#ifndef crypto_scalarmult_curve25519_ref_VERSION
#define crypto_scalarmult_curve25519_ref_VERSION "-"
#endif
#define crypto_scalarmult_curve25519_VERSION crypto_scalarmult_curve25519_ref_VERSION
#endif

View File

@ -0,0 +1,2 @@
#define CRYPTO_BYTES 32
#define CRYPTO_SCALARBYTES 32

View File

@ -0,0 +1,16 @@
/*
version 20081011
Matthew Dempsky
Public domain.
Derived from public domain code by D. J. Bernstein.
*/
#include "crypto_scalarmult.h"
const unsigned char base[32] = {9};
int crypto_scalarmult_base(unsigned char *q,
const unsigned char *n)
{
return crypto_scalarmult(q,n,base);
}

View File

@ -0,0 +1,18 @@
#ifndef crypto_scalarmult_H
#define crypto_scalarmult_H
#include "crypto_scalarmult_curve25519.h"
#define crypto_scalarmult crypto_scalarmult_curve25519
/* CHEESEBURGER crypto_scalarmult_curve25519 */
#define crypto_scalarmult_base crypto_scalarmult_curve25519_base
/* CHEESEBURGER crypto_scalarmult_curve25519_base */
#define crypto_scalarmult_BYTES crypto_scalarmult_curve25519_BYTES
/* CHEESEBURGER crypto_scalarmult_curve25519_BYTES */
#define crypto_scalarmult_SCALARBYTES crypto_scalarmult_curve25519_SCALARBYTES
/* CHEESEBURGER crypto_scalarmult_curve25519_SCALARBYTES */
#define crypto_scalarmult_PRIMITIVE "curve25519"
#define crypto_scalarmult_IMPLEMENTATION crypto_scalarmult_curve25519_IMPLEMENTATION
#define crypto_scalarmult_VERSION crypto_scalarmult_curve25519_VERSION
#endif

View File

@ -0,0 +1 @@
Matthew Dempsky (Mochi Media)

View File

@ -0,0 +1,265 @@
/*
version 20081011
Matthew Dempsky
Public domain.
Derived from public domain code by D. J. Bernstein.
*/
#include "crypto_scalarmult.h"
static void add(unsigned int out[32],const unsigned int a[32],const unsigned int b[32])
{
unsigned int j;
unsigned int u;
u = 0;
for (j = 0;j < 31;++j) { u += a[j] + b[j]; out[j] = u & 255; u >>= 8; }
u += a[31] + b[31]; out[31] = u;
}
static void sub(unsigned int out[32],const unsigned int a[32],const unsigned int b[32])
{
unsigned int j;
unsigned int u;
u = 218;
for (j = 0;j < 31;++j) {
u += a[j] + 65280 - b[j];
out[j] = u & 255;
u >>= 8;
}
u += a[31] - b[31];
out[31] = u;
}
static void squeeze(unsigned int a[32])
{
unsigned int j;
unsigned int u;
u = 0;
for (j = 0;j < 31;++j) { u += a[j]; a[j] = u & 255; u >>= 8; }
u += a[31]; a[31] = u & 127;
u = 19 * (u >> 7);
for (j = 0;j < 31;++j) { u += a[j]; a[j] = u & 255; u >>= 8; }
u += a[31]; a[31] = u;
}
static const unsigned int minusp[32] = {
19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128
} ;
static void freeze(unsigned int a[32])
{
unsigned int aorig[32];
unsigned int j;
unsigned int negative;
for (j = 0;j < 32;++j) aorig[j] = a[j];
add(a,a,minusp);
negative = -((a[31] >> 7) & 1);
for (j = 0;j < 32;++j) a[j] ^= negative & (aorig[j] ^ a[j]);
}
static void mult(unsigned int out[32],const unsigned int a[32],const unsigned int b[32])
{
unsigned int i;
unsigned int j;
unsigned int u;
for (i = 0;i < 32;++i) {
u = 0;
for (j = 0;j <= i;++j) u += a[j] * b[i - j];
for (j = i + 1;j < 32;++j) u += 38 * a[j] * b[i + 32 - j];
out[i] = u;
}
squeeze(out);
}
static void mult121665(unsigned int out[32],const unsigned int a[32])
{
unsigned int j;
unsigned int u;
u = 0;
for (j = 0;j < 31;++j) { u += 121665 * a[j]; out[j] = u & 255; u >>= 8; }
u += 121665 * a[31]; out[31] = u & 127;
u = 19 * (u >> 7);
for (j = 0;j < 31;++j) { u += out[j]; out[j] = u & 255; u >>= 8; }
u += out[j]; out[j] = u;
}
static void square(unsigned int out[32],const unsigned int a[32])
{
unsigned int i;
unsigned int j;
unsigned int u;
for (i = 0;i < 32;++i) {
u = 0;
for (j = 0;j < i - j;++j) u += a[j] * a[i - j];
for (j = i + 1;j < i + 32 - j;++j) u += 38 * a[j] * a[i + 32 - j];
u *= 2;
if ((i & 1) == 0) {
u += a[i / 2] * a[i / 2];
u += 38 * a[i / 2 + 16] * a[i / 2 + 16];
}
out[i] = u;
}
squeeze(out);
}
static void select(unsigned int p[64],unsigned int q[64],const unsigned int r[64],const unsigned int s[64],unsigned int b)
{
unsigned int j;
unsigned int t;
unsigned int bminus1;
bminus1 = b - 1;
for (j = 0;j < 64;++j) {
t = bminus1 & (r[j] ^ s[j]);
p[j] = s[j] ^ t;
q[j] = r[j] ^ t;
}
}
static void mainloop(unsigned int work[64],const unsigned char e[32])
{
unsigned int xzm1[64];
unsigned int xzm[64];
unsigned int xzmb[64];
unsigned int xzm1b[64];
unsigned int xznb[64];
unsigned int xzn1b[64];
unsigned int a0[64];
unsigned int a1[64];
unsigned int b0[64];
unsigned int b1[64];
unsigned int c1[64];
unsigned int r[32];
unsigned int s[32];
unsigned int t[32];
unsigned int u[32];
unsigned int i;
unsigned int j;
unsigned int b;
int pos;
for (j = 0;j < 32;++j) xzm1[j] = work[j];
xzm1[32] = 1;
for (j = 33;j < 64;++j) xzm1[j] = 0;
xzm[0] = 1;
for (j = 1;j < 64;++j) xzm[j] = 0;
for (pos = 254;pos >= 0;--pos) {
b = e[pos / 8] >> (pos & 7);
b &= 1;
select(xzmb,xzm1b,xzm,xzm1,b);
add(a0,xzmb,xzmb + 32);
sub(a0 + 32,xzmb,xzmb + 32);
add(a1,xzm1b,xzm1b + 32);
sub(a1 + 32,xzm1b,xzm1b + 32);
square(b0,a0);
square(b0 + 32,a0 + 32);
mult(b1,a1,a0 + 32);
mult(b1 + 32,a1 + 32,a0);
add(c1,b1,b1 + 32);
sub(c1 + 32,b1,b1 + 32);
square(r,c1 + 32);
sub(s,b0,b0 + 32);
mult121665(t,s);
add(u,t,b0);
mult(xznb,b0,b0 + 32);
mult(xznb + 32,s,u);
square(xzn1b,c1);
mult(xzn1b + 32,r,work);
select(xzm,xzm1,xznb,xzn1b,b);
}
for (j = 0;j < 64;++j) work[j] = xzm[j];
}
static void recip(unsigned int out[32],const unsigned int z[32])
{
unsigned int z2[32];
unsigned int z9[32];
unsigned int z11[32];
unsigned int z2_5_0[32];
unsigned int z2_10_0[32];
unsigned int z2_20_0[32];
unsigned int z2_50_0[32];
unsigned int z2_100_0[32];
unsigned int t0[32];
unsigned int t1[32];
int i;
/* 2 */ square(z2,z);
/* 4 */ square(t1,z2);
/* 8 */ square(t0,t1);
/* 9 */ mult(z9,t0,z);
/* 11 */ mult(z11,z9,z2);
/* 22 */ square(t0,z11);
/* 2^5 - 2^0 = 31 */ mult(z2_5_0,t0,z9);
/* 2^6 - 2^1 */ square(t0,z2_5_0);
/* 2^7 - 2^2 */ square(t1,t0);
/* 2^8 - 2^3 */ square(t0,t1);
/* 2^9 - 2^4 */ square(t1,t0);
/* 2^10 - 2^5 */ square(t0,t1);
/* 2^10 - 2^0 */ mult(z2_10_0,t0,z2_5_0);
/* 2^11 - 2^1 */ square(t0,z2_10_0);
/* 2^12 - 2^2 */ square(t1,t0);
/* 2^20 - 2^10 */ for (i = 2;i < 10;i += 2) { square(t0,t1); square(t1,t0); }
/* 2^20 - 2^0 */ mult(z2_20_0,t1,z2_10_0);
/* 2^21 - 2^1 */ square(t0,z2_20_0);
/* 2^22 - 2^2 */ square(t1,t0);
/* 2^40 - 2^20 */ for (i = 2;i < 20;i += 2) { square(t0,t1); square(t1,t0); }
/* 2^40 - 2^0 */ mult(t0,t1,z2_20_0);
/* 2^41 - 2^1 */ square(t1,t0);
/* 2^42 - 2^2 */ square(t0,t1);
/* 2^50 - 2^10 */ for (i = 2;i < 10;i += 2) { square(t1,t0); square(t0,t1); }
/* 2^50 - 2^0 */ mult(z2_50_0,t0,z2_10_0);
/* 2^51 - 2^1 */ square(t0,z2_50_0);
/* 2^52 - 2^2 */ square(t1,t0);
/* 2^100 - 2^50 */ for (i = 2;i < 50;i += 2) { square(t0,t1); square(t1,t0); }
/* 2^100 - 2^0 */ mult(z2_100_0,t1,z2_50_0);
/* 2^101 - 2^1 */ square(t1,z2_100_0);
/* 2^102 - 2^2 */ square(t0,t1);
/* 2^200 - 2^100 */ for (i = 2;i < 100;i += 2) { square(t1,t0); square(t0,t1); }
/* 2^200 - 2^0 */ mult(t1,t0,z2_100_0);
/* 2^201 - 2^1 */ square(t0,t1);
/* 2^202 - 2^2 */ square(t1,t0);
/* 2^250 - 2^50 */ for (i = 2;i < 50;i += 2) { square(t0,t1); square(t1,t0); }
/* 2^250 - 2^0 */ mult(t0,t1,z2_50_0);
/* 2^251 - 2^1 */ square(t1,t0);
/* 2^252 - 2^2 */ square(t0,t1);
/* 2^253 - 2^3 */ square(t1,t0);
/* 2^254 - 2^4 */ square(t0,t1);
/* 2^255 - 2^5 */ square(t1,t0);
/* 2^255 - 21 */ mult(out,t1,z11);
}
int crypto_scalarmult(unsigned char *q,
const unsigned char *n,
const unsigned char *p)
{
unsigned int work[96];
unsigned char e[32];
unsigned int i;
for (i = 0;i < 32;++i) e[i] = n[i];
e[0] &= 248;
e[31] &= 127;
e[31] |= 64;
for (i = 0;i < 32;++i) work[i] = p[i];
mainloop(work,e);
recip(work + 32,work + 32);
mult(work + 64,work,work + 32);
freeze(work + 64);
for (i = 0;i < 32;++i) q[i] = work[64 + i];
return 0;
}

View File

@ -0,0 +1,38 @@
#ifndef crypto_secretbox_xsalsa20poly1305_H
#define crypto_secretbox_xsalsa20poly1305_H
#define crypto_secretbox_xsalsa20poly1305_ref_KEYBYTES 32
#define crypto_secretbox_xsalsa20poly1305_ref_NONCEBYTES 24
#define crypto_secretbox_xsalsa20poly1305_ref_ZEROBYTES 32
#define crypto_secretbox_xsalsa20poly1305_ref_BOXZEROBYTES 16
#ifdef __cplusplus
#include <string>
extern std::string crypto_secretbox_xsalsa20poly1305_ref(const std::string &,const std::string &,const std::string &);
extern std::string crypto_secretbox_xsalsa20poly1305_ref_open(const std::string &,const std::string &,const std::string &);
extern "C" {
#endif
extern int crypto_secretbox_xsalsa20poly1305_ref(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_secretbox_xsalsa20poly1305_ref_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_secretbox_xsalsa20poly1305 crypto_secretbox_xsalsa20poly1305_ref
/* POTATO crypto_secretbox_xsalsa20poly1305_ref crypto_secretbox_xsalsa20poly1305_ref crypto_secretbox_xsalsa20poly1305 */
#define crypto_secretbox_xsalsa20poly1305_open crypto_secretbox_xsalsa20poly1305_ref_open
/* POTATO crypto_secretbox_xsalsa20poly1305_ref_open crypto_secretbox_xsalsa20poly1305_ref crypto_secretbox_xsalsa20poly1305 */
#define crypto_secretbox_xsalsa20poly1305_KEYBYTES crypto_secretbox_xsalsa20poly1305_ref_KEYBYTES
/* POTATO crypto_secretbox_xsalsa20poly1305_ref_KEYBYTES crypto_secretbox_xsalsa20poly1305_ref crypto_secretbox_xsalsa20poly1305 */
#define crypto_secretbox_xsalsa20poly1305_NONCEBYTES crypto_secretbox_xsalsa20poly1305_ref_NONCEBYTES
/* POTATO crypto_secretbox_xsalsa20poly1305_ref_NONCEBYTES crypto_secretbox_xsalsa20poly1305_ref crypto_secretbox_xsalsa20poly1305 */
#define crypto_secretbox_xsalsa20poly1305_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ref_ZEROBYTES
/* POTATO crypto_secretbox_xsalsa20poly1305_ref_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ref crypto_secretbox_xsalsa20poly1305 */
#define crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_ref_BOXZEROBYTES
/* POTATO crypto_secretbox_xsalsa20poly1305_ref_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_ref crypto_secretbox_xsalsa20poly1305 */
#define crypto_secretbox_xsalsa20poly1305_IMPLEMENTATION "crypto_secretbox/xsalsa20poly1305/ref"
#ifndef crypto_secretbox_xsalsa20poly1305_ref_VERSION
#define crypto_secretbox_xsalsa20poly1305_ref_VERSION "-"
#endif
#define crypto_secretbox_xsalsa20poly1305_VERSION crypto_secretbox_xsalsa20poly1305_ref_VERSION
#endif

View File

@ -0,0 +1,4 @@
#define CRYPTO_KEYBYTES 32
#define CRYPTO_NONCEBYTES 24
#define CRYPTO_ZEROBYTES 32
#define CRYPTO_BOXZEROBYTES 16

View File

@ -0,0 +1,35 @@
#include "crypto_onetimeauth_poly1305.h"
#include "crypto_stream_xsalsa20.h"
#include "crypto_secretbox.h"
int crypto_secretbox(
unsigned char *c,
const unsigned char *m,unsigned long long mlen,
const unsigned char *n,
const unsigned char *k
)
{
int i;
if (mlen < 32) return -1;
crypto_stream_xsalsa20_xor(c,m,mlen,n,k);
crypto_onetimeauth_poly1305(c + 16,c + 32,mlen - 32,c);
for (i = 0;i < 16;++i) c[i] = 0;
return 0;
}
int crypto_secretbox_open(
unsigned char *m,
const unsigned char *c,unsigned long long clen,
const unsigned char *n,
const unsigned char *k
)
{
int i;
unsigned char subkey[32];
if (clen < 32) return -1;
crypto_stream_xsalsa20(subkey,32,n,k);
if (crypto_onetimeauth_poly1305_verify(c + 16,c + 32,clen - 32,subkey) != 0) return -1;
crypto_stream_xsalsa20_xor(m,c,clen,n,k);
for (i = 0;i < 32;++i) m[i] = 0;
return 0;
}

View File

@ -0,0 +1,22 @@
#ifndef crypto_secretbox_H
#define crypto_secretbox_H
#include "crypto_secretbox_xsalsa20poly1305.h"
#define crypto_secretbox crypto_secretbox_xsalsa20poly1305
/* CHEESEBURGER crypto_secretbox_xsalsa20poly1305 */
#define crypto_secretbox_open crypto_secretbox_xsalsa20poly1305_open
/* CHEESEBURGER crypto_secretbox_xsalsa20poly1305_open */
#define crypto_secretbox_KEYBYTES crypto_secretbox_xsalsa20poly1305_KEYBYTES
/* CHEESEBURGER crypto_secretbox_xsalsa20poly1305_KEYBYTES */
#define crypto_secretbox_NONCEBYTES crypto_secretbox_xsalsa20poly1305_NONCEBYTES
/* CHEESEBURGER crypto_secretbox_xsalsa20poly1305_NONCEBYTES */
#define crypto_secretbox_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ZEROBYTES
/* CHEESEBURGER crypto_secretbox_xsalsa20poly1305_ZEROBYTES */
#define crypto_secretbox_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES
/* CHEESEBURGER crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES */
#define crypto_secretbox_PRIMITIVE "xsalsa20poly1305"
#define crypto_secretbox_IMPLEMENTATION crypto_secretbox_xsalsa20poly1305_IMPLEMENTATION
#define crypto_secretbox_VERSION crypto_secretbox_xsalsa20poly1305_VERSION
#endif

View File

@ -0,0 +1,39 @@
#ifndef crypto_sign_edwards25519sha512batch_H
#define crypto_sign_edwards25519sha512batch_H
#define crypto_sign_edwards25519sha512batch_ref_SECRETKEYBYTES 64
#define crypto_sign_edwards25519sha512batch_ref_PUBLICKEYBYTES 32
#define crypto_sign_edwards25519sha512batch_ref_BYTES 64
#ifdef __cplusplus
#include <string>
extern std::string crypto_sign_edwards25519sha512batch_ref(const std::string &,const std::string &);
extern std::string crypto_sign_edwards25519sha512batch_ref_open(const std::string &,const std::string &);
extern std::string crypto_sign_edwards25519sha512batch_ref_keypair(std::string *);
extern "C" {
#endif
extern int crypto_sign_edwards25519sha512batch_ref(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_sign_edwards25519sha512batch_ref_open(unsigned char *,unsigned long long *,const unsigned char *,unsigned long long,const unsigned char *);
extern int crypto_sign_edwards25519sha512batch_ref_keypair(unsigned char *,unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_sign_edwards25519sha512batch crypto_sign_edwards25519sha512batch_ref
/* POTATO crypto_sign_edwards25519sha512batch_ref crypto_sign_edwards25519sha512batch_ref crypto_sign_edwards25519sha512batch */
#define crypto_sign_edwards25519sha512batch_open crypto_sign_edwards25519sha512batch_ref_open
/* POTATO crypto_sign_edwards25519sha512batch_ref_open crypto_sign_edwards25519sha512batch_ref crypto_sign_edwards25519sha512batch */
#define crypto_sign_edwards25519sha512batch_keypair crypto_sign_edwards25519sha512batch_ref_keypair
/* POTATO crypto_sign_edwards25519sha512batch_ref_keypair crypto_sign_edwards25519sha512batch_ref crypto_sign_edwards25519sha512batch */
#define crypto_sign_edwards25519sha512batch_BYTES crypto_sign_edwards25519sha512batch_ref_BYTES
/* POTATO crypto_sign_edwards25519sha512batch_ref_BYTES crypto_sign_edwards25519sha512batch_ref crypto_sign_edwards25519sha512batch */
#define crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES crypto_sign_edwards25519sha512batch_ref_PUBLICKEYBYTES
/* POTATO crypto_sign_edwards25519sha512batch_ref_PUBLICKEYBYTES crypto_sign_edwards25519sha512batch_ref crypto_sign_edwards25519sha512batch */
#define crypto_sign_edwards25519sha512batch_SECRETKEYBYTES crypto_sign_edwards25519sha512batch_ref_SECRETKEYBYTES
/* POTATO crypto_sign_edwards25519sha512batch_ref_SECRETKEYBYTES crypto_sign_edwards25519sha512batch_ref crypto_sign_edwards25519sha512batch */
#define crypto_sign_edwards25519sha512batch_IMPLEMENTATION "crypto_sign/edwards25519sha512batch/ref"
#ifndef crypto_sign_edwards25519sha512batch_ref_VERSION
#define crypto_sign_edwards25519sha512batch_ref_VERSION "-"
#endif
#define crypto_sign_edwards25519sha512batch_VERSION crypto_sign_edwards25519sha512batch_ref_VERSION
#endif

View File

@ -0,0 +1,3 @@
#define CRYPTO_SECRETKEYBYTES 64
#define CRYPTO_PUBLICKEYBYTES 32
#define CRYPTO_BYTES 64

View File

@ -0,0 +1,22 @@
#ifndef crypto_sign_H
#define crypto_sign_H
#include "crypto_sign_edwards25519sha512batch.h"
#define crypto_sign crypto_sign_edwards25519sha512batch
/* CHEESEBURGER crypto_sign_edwards25519sha512batch */
#define crypto_sign_open crypto_sign_edwards25519sha512batch_open
/* CHEESEBURGER crypto_sign_edwards25519sha512batch_open */
#define crypto_sign_keypair crypto_sign_edwards25519sha512batch_keypair
/* CHEESEBURGER crypto_sign_edwards25519sha512batch_keypair */
#define crypto_sign_BYTES crypto_sign_edwards25519sha512batch_BYTES
/* CHEESEBURGER crypto_sign_edwards25519sha512batch_BYTES */
#define crypto_sign_PUBLICKEYBYTES crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES
/* CHEESEBURGER crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES */
#define crypto_sign_SECRETKEYBYTES crypto_sign_edwards25519sha512batch_SECRETKEYBYTES
/* CHEESEBURGER crypto_sign_edwards25519sha512batch_SECRETKEYBYTES */
#define crypto_sign_PRIMITIVE "edwards25519sha512batch"
#define crypto_sign_IMPLEMENTATION crypto_sign_edwards25519sha512batch_IMPLEMENTATION
#define crypto_sign_VERSION crypto_sign_edwards25519sha512batch_VERSION
#endif

View File

@ -0,0 +1,345 @@
#include "fe25519.h"
#define WINDOWSIZE 4 /* Should be 1,2, or 4 */
#define WINDOWMASK ((1<<WINDOWSIZE)-1)
static void reduce_add_sub(fe25519 *r)
{
crypto_uint32 t;
int i,rep;
for(rep=0;rep<4;rep++)
{
t = r->v[31] >> 7;
r->v[31] &= 127;
t *= 19;
r->v[0] += t;
for(i=0;i<31;i++)
{
t = r->v[i] >> 8;
r->v[i+1] += t;
r->v[i] &= 255;
}
}
}
static void reduce_mul(fe25519 *r)
{
crypto_uint32 t;
int i,rep;
for(rep=0;rep<2;rep++)
{
t = r->v[31] >> 7;
r->v[31] &= 127;
t *= 19;
r->v[0] += t;
for(i=0;i<31;i++)
{
t = r->v[i] >> 8;
r->v[i+1] += t;
r->v[i] &= 255;
}
}
}
/* reduction modulo 2^255-19 */
static void freeze(fe25519 *r)
{
int i;
unsigned int m = (r->v[31] == 127);
for(i=30;i>1;i--)
m *= (r->v[i] == 255);
m *= (r->v[0] >= 237);
r->v[31] -= m*127;
for(i=30;i>0;i--)
r->v[i] -= m*255;
r->v[0] -= m*237;
}
/*freeze input before calling isone*/
static int isone(const fe25519 *x)
{
int i;
int r = (x->v[0] == 1);
for(i=1;i<32;i++)
r *= (x->v[i] == 0);
return r;
}
/*freeze input before calling iszero*/
static int iszero(const fe25519 *x)
{
int i;
int r = (x->v[0] == 0);
for(i=1;i<32;i++)
r *= (x->v[i] == 0);
return r;
}
static int issquare(const fe25519 *x)
{
unsigned char e[32] = {0xf6,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f}; /* (p-1)/2 */
fe25519 t;
fe25519_pow(&t,x,e);
freeze(&t);
return isone(&t) || iszero(&t);
}
void fe25519_unpack(fe25519 *r, const unsigned char x[32])
{
int i;
for(i=0;i<32;i++) r->v[i] = x[i];
r->v[31] &= 127;
}
/* Assumes input x being reduced mod 2^255 */
void fe25519_pack(unsigned char r[32], const fe25519 *x)
{
int i;
for(i=0;i<32;i++)
r[i] = x->v[i];
/* freeze byte array */
unsigned int m = (r[31] == 127); /* XXX: some compilers might use branches; fix */
for(i=30;i>1;i--)
m *= (r[i] == 255);
m *= (r[0] >= 237);
r[31] -= m*127;
for(i=30;i>0;i--)
r[i] -= m*255;
r[0] -= m*237;
}
void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b)
{
unsigned char nb = 1-b;
int i;
for(i=0;i<32;i++) r->v[i] = nb * r->v[i] + b * x->v[i];
}
unsigned char fe25519_getparity(const fe25519 *x)
{
fe25519 t;
int i;
for(i=0;i<32;i++) t.v[i] = x->v[i];
freeze(&t);
return t.v[0] & 1;
}
void fe25519_setone(fe25519 *r)
{
int i;
r->v[0] = 1;
for(i=1;i<32;i++) r->v[i]=0;
}
void fe25519_setzero(fe25519 *r)
{
int i;
for(i=0;i<32;i++) r->v[i]=0;
}
void fe25519_neg(fe25519 *r, const fe25519 *x)
{
fe25519 t;
int i;
for(i=0;i<32;i++) t.v[i]=x->v[i];
fe25519_setzero(r);
fe25519_sub(r, r, &t);
}
void fe25519_add(fe25519 *r, const fe25519 *x, const fe25519 *y)
{
int i;
for(i=0;i<32;i++) r->v[i] = x->v[i] + y->v[i];
reduce_add_sub(r);
}
void fe25519_sub(fe25519 *r, const fe25519 *x, const fe25519 *y)
{
int i;
crypto_uint32 t[32];
t[0] = x->v[0] + 0x1da;
t[31] = x->v[31] + 0xfe;
for(i=1;i<31;i++) t[i] = x->v[i] + 0x1fe;
for(i=0;i<32;i++) r->v[i] = t[i] - y->v[i];
reduce_add_sub(r);
}
void fe25519_mul(fe25519 *r, const fe25519 *x, const fe25519 *y)
{
int i,j;
crypto_uint32 t[63];
for(i=0;i<63;i++)t[i] = 0;
for(i=0;i<32;i++)
for(j=0;j<32;j++)
t[i+j] += x->v[i] * y->v[j];
for(i=32;i<63;i++)
r->v[i-32] = t[i-32] + 38*t[i];
r->v[31] = t[31]; /* result now in r[0]...r[31] */
reduce_mul(r);
}
void fe25519_square(fe25519 *r, const fe25519 *x)
{
fe25519_mul(r, x, x);
}
/*XXX: Make constant time! */
void fe25519_pow(fe25519 *r, const fe25519 *x, const unsigned char *e)
{
/*
fe25519 g;
fe25519_setone(&g);
int i;
unsigned char j;
for(i=32;i>0;i--)
{
for(j=128;j>0;j>>=1)
{
fe25519_square(&g,&g);
if(e[i-1] & j)
fe25519_mul(&g,&g,x);
}
}
for(i=0;i<32;i++) r->v[i] = g.v[i];
*/
fe25519 g;
fe25519_setone(&g);
int i,j,k;
fe25519 pre[(1 << WINDOWSIZE)];
fe25519 t;
unsigned char w;
// Precomputation
fe25519_setone(pre);
pre[1] = *x;
for(i=2;i<(1<<WINDOWSIZE);i+=2)
{
fe25519_square(pre+i, pre+i/2);
fe25519_mul(pre+i+1, pre+i, pre+1);
}
// Fixed-window scalar multiplication
for(i=32;i>0;i--)
{
for(j=8-WINDOWSIZE;j>=0;j-=WINDOWSIZE)
{
for(k=0;k<WINDOWSIZE;k++)
fe25519_square(&g, &g);
// Cache-timing resistant loading of precomputed value:
w = (e[i-1]>>j) & WINDOWMASK;
t = pre[0];
for(k=1;k<(1<<WINDOWSIZE);k++)
fe25519_cmov(&t, &pre[k], k==w);
fe25519_mul(&g, &g, &t);
}
}
*r = g;
}
/* Return 0 on success, 1 otherwise */
int fe25519_sqrt_vartime(fe25519 *r, const fe25519 *x, unsigned char parity)
{
/* See HAC, Alg. 3.37 */
if (!issquare(x)) return -1;
unsigned char e[32] = {0xfb,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1f}; /* (p-1)/4 */
unsigned char e2[32] = {0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0f}; /* (p+3)/8 */
unsigned char e3[32] = {0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0f}; /* (p-5)/8 */
fe25519 p = {{0}};
fe25519 d;
int i;
fe25519_pow(&d,x,e);
freeze(&d);
if(isone(&d))
fe25519_pow(r,x,e2);
else
{
for(i=0;i<32;i++)
d.v[i] = 4*x->v[i];
fe25519_pow(&d,&d,e3);
for(i=0;i<32;i++)
r->v[i] = 2*x->v[i];
fe25519_mul(r,r,&d);
}
freeze(r);
if((r->v[0] & 1) != (parity & 1))
{
fe25519_sub(r,&p,r);
}
return 0;
}
void fe25519_invert(fe25519 *r, const fe25519 *x)
{
fe25519 z2;
fe25519 z9;
fe25519 z11;
fe25519 z2_5_0;
fe25519 z2_10_0;
fe25519 z2_20_0;
fe25519 z2_50_0;
fe25519 z2_100_0;
fe25519 t0;
fe25519 t1;
int i;
/* 2 */ fe25519_square(&z2,x);
/* 4 */ fe25519_square(&t1,&z2);
/* 8 */ fe25519_square(&t0,&t1);
/* 9 */ fe25519_mul(&z9,&t0,x);
/* 11 */ fe25519_mul(&z11,&z9,&z2);
/* 22 */ fe25519_square(&t0,&z11);
/* 2^5 - 2^0 = 31 */ fe25519_mul(&z2_5_0,&t0,&z9);
/* 2^6 - 2^1 */ fe25519_square(&t0,&z2_5_0);
/* 2^7 - 2^2 */ fe25519_square(&t1,&t0);
/* 2^8 - 2^3 */ fe25519_square(&t0,&t1);
/* 2^9 - 2^4 */ fe25519_square(&t1,&t0);
/* 2^10 - 2^5 */ fe25519_square(&t0,&t1);
/* 2^10 - 2^0 */ fe25519_mul(&z2_10_0,&t0,&z2_5_0);
/* 2^11 - 2^1 */ fe25519_square(&t0,&z2_10_0);
/* 2^12 - 2^2 */ fe25519_square(&t1,&t0);
/* 2^20 - 2^10 */ for (i = 2;i < 10;i += 2) { fe25519_square(&t0,&t1); fe25519_square(&t1,&t0); }
/* 2^20 - 2^0 */ fe25519_mul(&z2_20_0,&t1,&z2_10_0);
/* 2^21 - 2^1 */ fe25519_square(&t0,&z2_20_0);
/* 2^22 - 2^2 */ fe25519_square(&t1,&t0);
/* 2^40 - 2^20 */ for (i = 2;i < 20;i += 2) { fe25519_square(&t0,&t1); fe25519_square(&t1,&t0); }
/* 2^40 - 2^0 */ fe25519_mul(&t0,&t1,&z2_20_0);
/* 2^41 - 2^1 */ fe25519_square(&t1,&t0);
/* 2^42 - 2^2 */ fe25519_square(&t0,&t1);
/* 2^50 - 2^10 */ for (i = 2;i < 10;i += 2) { fe25519_square(&t1,&t0); fe25519_square(&t0,&t1); }
/* 2^50 - 2^0 */ fe25519_mul(&z2_50_0,&t0,&z2_10_0);
/* 2^51 - 2^1 */ fe25519_square(&t0,&z2_50_0);
/* 2^52 - 2^2 */ fe25519_square(&t1,&t0);
/* 2^100 - 2^50 */ for (i = 2;i < 50;i += 2) { fe25519_square(&t0,&t1); fe25519_square(&t1,&t0); }
/* 2^100 - 2^0 */ fe25519_mul(&z2_100_0,&t1,&z2_50_0);
/* 2^101 - 2^1 */ fe25519_square(&t1,&z2_100_0);
/* 2^102 - 2^2 */ fe25519_square(&t0,&t1);
/* 2^200 - 2^100 */ for (i = 2;i < 100;i += 2) { fe25519_square(&t1,&t0); fe25519_square(&t0,&t1); }
/* 2^200 - 2^0 */ fe25519_mul(&t1,&t0,&z2_100_0);
/* 2^201 - 2^1 */ fe25519_square(&t0,&t1);
/* 2^202 - 2^2 */ fe25519_square(&t1,&t0);
/* 2^250 - 2^50 */ for (i = 2;i < 50;i += 2) { fe25519_square(&t0,&t1); fe25519_square(&t1,&t0); }
/* 2^250 - 2^0 */ fe25519_mul(&t0,&t1,&z2_50_0);
/* 2^251 - 2^1 */ fe25519_square(&t1,&t0);
/* 2^252 - 2^2 */ fe25519_square(&t0,&t1);
/* 2^253 - 2^3 */ fe25519_square(&t1,&t0);
/* 2^254 - 2^4 */ fe25519_square(&t0,&t1);
/* 2^255 - 2^5 */ fe25519_square(&t1,&t0);
/* 2^255 - 21 */ fe25519_mul(r,&t1,&z11);
}

View File

@ -0,0 +1,54 @@
#ifndef FE25519_H
#define FE25519_H
#define fe25519 crypto_sign_edwards25519sha512batch_fe25519
#define fe25519_unpack crypto_sign_edwards25519sha512batch_fe25519_unpack
#define fe25519_pack crypto_sign_edwards25519sha512batch_fe25519_pack
#define fe25519_cmov crypto_sign_edwards25519sha512batch_fe25519_cmov
#define fe25519_setone crypto_sign_edwards25519sha512batch_fe25519_setone
#define fe25519_setzero crypto_sign_edwards25519sha512batch_fe25519_setzero
#define fe25519_neg crypto_sign_edwards25519sha512batch_fe25519_neg
#define fe25519_getparity crypto_sign_edwards25519sha512batch_fe25519_getparity
#define fe25519_add crypto_sign_edwards25519sha512batch_fe25519_add
#define fe25519_sub crypto_sign_edwards25519sha512batch_fe25519_sub
#define fe25519_mul crypto_sign_edwards25519sha512batch_fe25519_mul
#define fe25519_square crypto_sign_edwards25519sha512batch_fe25519_square
#define fe25519_pow crypto_sign_edwards25519sha512batch_fe25519_pow
#define fe25519_sqrt_vartime crypto_sign_edwards25519sha512batch_fe25519_sqrt_vartime
#define fe25519_invert crypto_sign_edwards25519sha512batch_fe25519_invert
#include "crypto_uint32.h"
typedef struct {
crypto_uint32 v[32];
} fe25519;
void fe25519_unpack(fe25519 *r, const unsigned char x[32]);
void fe25519_pack(unsigned char r[32], const fe25519 *x);
void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b);
void fe25519_setone(fe25519 *r);
void fe25519_setzero(fe25519 *r);
void fe25519_neg(fe25519 *r, const fe25519 *x);
unsigned char fe25519_getparity(const fe25519 *x);
void fe25519_add(fe25519 *r, const fe25519 *x, const fe25519 *y);
void fe25519_sub(fe25519 *r, const fe25519 *x, const fe25519 *y);
void fe25519_mul(fe25519 *r, const fe25519 *x, const fe25519 *y);
void fe25519_square(fe25519 *r, const fe25519 *x);
void fe25519_pow(fe25519 *r, const fe25519 *x, const unsigned char *e);
int fe25519_sqrt_vartime(fe25519 *r, const fe25519 *x, unsigned char parity);
void fe25519_invert(fe25519 *r, const fe25519 *x);
#endif

View File

@ -0,0 +1,227 @@
#include "fe25519.h"
#include "sc25519.h"
#include "ge25519.h"
/*
* Arithmetic on the twisted Edwards curve -x^2 + y^2 = 1 + dx^2y^2
* with d = -(121665/121666) = 37095705934669439343138083508754565189542113879843219016388785533085940283555
* Base point: (15112221349535400772501151409588531511454012693041857206046113283949847762202,46316835694926478169428394003475163141307993866256225615783033603165251855960);
*/
typedef struct
{
fe25519 x;
fe25519 z;
fe25519 y;
fe25519 t;
} ge25519_p1p1;
typedef struct
{
fe25519 x;
fe25519 y;
fe25519 z;
} ge25519_p2;
#define ge25519_p3 ge25519
/* Windowsize for fixed-window scalar multiplication */
#define WINDOWSIZE 2 /* Should be 1,2, or 4 */
#define WINDOWMASK ((1<<WINDOWSIZE)-1)
/* packed parameter d in the Edwards curve equation */
static const unsigned char ecd[32] = {0xA3, 0x78, 0x59, 0x13, 0xCA, 0x4D, 0xEB, 0x75, 0xAB, 0xD8, 0x41, 0x41, 0x4D, 0x0A, 0x70, 0x00,
0x98, 0xE8, 0x79, 0x77, 0x79, 0x40, 0xC7, 0x8C, 0x73, 0xFE, 0x6F, 0x2B, 0xEE, 0x6C, 0x03, 0x52};
/* Packed coordinates of the base point */
static const unsigned char ge25519_base_x[32] = {0x1A, 0xD5, 0x25, 0x8F, 0x60, 0x2D, 0x56, 0xC9, 0xB2, 0xA7, 0x25, 0x95, 0x60, 0xC7, 0x2C, 0x69,
0x5C, 0xDC, 0xD6, 0xFD, 0x31, 0xE2, 0xA4, 0xC0, 0xFE, 0x53, 0x6E, 0xCD, 0xD3, 0x36, 0x69, 0x21};
static const unsigned char ge25519_base_y[32] = {0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66};
static const unsigned char ge25519_base_z[32] = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static const unsigned char ge25519_base_t[32] = {0xA3, 0xDD, 0xB7, 0xA5, 0xB3, 0x8A, 0xDE, 0x6D, 0xF5, 0x52, 0x51, 0x77, 0x80, 0x9F, 0xF0, 0x20,
0x7D, 0xE3, 0xAB, 0x64, 0x8E, 0x4E, 0xEA, 0x66, 0x65, 0x76, 0x8B, 0xD7, 0x0F, 0x5F, 0x87, 0x67};
/* Packed coordinates of the neutral element */
static const unsigned char ge25519_neutral_x[32] = {0};
static const unsigned char ge25519_neutral_y[32] = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static const unsigned char ge25519_neutral_z[32] = {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static const unsigned char ge25519_neutral_t[32] = {0};
static void p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p)
{
fe25519_mul(&r->x, &p->x, &p->t);
fe25519_mul(&r->y, &p->y, &p->z);
fe25519_mul(&r->z, &p->z, &p->t);
}
static void p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p)
{
p1p1_to_p2((ge25519_p2 *)r, p);
fe25519_mul(&r->t, &p->x, &p->y);
}
/* Constant-time version of: if(b) r = p */
static void cmov_p3(ge25519_p3 *r, const ge25519_p3 *p, unsigned char b)
{
fe25519_cmov(&r->x, &p->x, b);
fe25519_cmov(&r->y, &p->y, b);
fe25519_cmov(&r->z, &p->z, b);
fe25519_cmov(&r->t, &p->t, b);
}
/* See http://www.hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html#doubling-dbl-2008-hwcd */
static void dbl_p1p1(ge25519_p1p1 *r, const ge25519_p2 *p)
{
fe25519 a,b,c,d;
fe25519_square(&a, &p->x);
fe25519_square(&b, &p->y);
fe25519_square(&c, &p->z);
fe25519_add(&c, &c, &c);
fe25519_neg(&d, &a);
fe25519_add(&r->x, &p->x, &p->y);
fe25519_square(&r->x, &r->x);
fe25519_sub(&r->x, &r->x, &a);
fe25519_sub(&r->x, &r->x, &b);
fe25519_add(&r->z, &d, &b);
fe25519_sub(&r->t, &r->z, &c);
fe25519_sub(&r->y, &d, &b);
}
static void add_p1p1(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_p3 *q)
{
fe25519 a, b, c, d, t, fd;
fe25519_unpack(&fd, ecd);
fe25519_sub(&a, &p->y, &p->x); // A = (Y1-X1)*(Y2-X2)
fe25519_sub(&t, &q->y, &q->x);
fe25519_mul(&a, &a, &t);
fe25519_add(&b, &p->x, &p->y); // B = (Y1+X1)*(Y2+X2)
fe25519_add(&t, &q->x, &q->y);
fe25519_mul(&b, &b, &t);
fe25519_mul(&c, &p->t, &q->t); //C = T1*k*T2
fe25519_mul(&c, &c, &fd);
fe25519_add(&c, &c, &c); //XXX: Can save this addition by precomputing 2*ecd
fe25519_mul(&d, &p->z, &q->z); //D = Z1*2*Z2
fe25519_add(&d, &d, &d);
fe25519_sub(&r->x, &b, &a); // E = B-A
fe25519_sub(&r->t, &d, &c); // F = D-C
fe25519_add(&r->z, &d, &c); // G = D+C
fe25519_add(&r->y, &b, &a); // H = B+A
}
/* ********************************************************************
* EXPORTED FUNCTIONS
******************************************************************** */
/* return 0 on success, -1 otherwise */
int ge25519_unpack_vartime(ge25519_p3 *r, const unsigned char p[32])
{
int ret;
fe25519 t, fd;
fe25519_setone(&r->z);
fe25519_unpack(&fd, ecd);
unsigned char par = p[31] >> 7;
fe25519_unpack(&r->y, p);
fe25519_square(&r->x, &r->y);
fe25519_mul(&t, &r->x, &fd);
fe25519_sub(&r->x, &r->x, &r->z);
fe25519_add(&t, &r->z, &t);
fe25519_invert(&t, &t);
fe25519_mul(&r->x, &r->x, &t);
ret = fe25519_sqrt_vartime(&r->x, &r->x, par);
fe25519_mul(&r->t, &r->x, &r->y);
return ret;
}
void ge25519_pack(unsigned char r[32], const ge25519_p3 *p)
{
fe25519 tx, ty, zi;
fe25519_invert(&zi, &p->z);
fe25519_mul(&tx, &p->x, &zi);
fe25519_mul(&ty, &p->y, &zi);
fe25519_pack(r, &ty);
r[31] ^= fe25519_getparity(&tx) << 7;
}
void ge25519_add(ge25519_p3 *r, const ge25519_p3 *p, const ge25519_p3 *q)
{
ge25519_p1p1 grp1p1;
add_p1p1(&grp1p1, p, q);
p1p1_to_p3(r, &grp1p1);
}
void ge25519_double(ge25519_p3 *r, const ge25519_p3 *p)
{
ge25519_p1p1 grp1p1;
dbl_p1p1(&grp1p1, (ge25519_p2 *)p);
p1p1_to_p3(r, &grp1p1);
}
void ge25519_scalarmult(ge25519_p3 *r, const ge25519_p3 *p, const sc25519 *s)
{
int i,j,k;
ge25519_p3 g;
fe25519_unpack(&g.x, ge25519_neutral_x);
fe25519_unpack(&g.y, ge25519_neutral_y);
fe25519_unpack(&g.z, ge25519_neutral_z);
fe25519_unpack(&g.t, ge25519_neutral_t);
ge25519_p3 pre[(1 << WINDOWSIZE)];
ge25519_p3 t;
ge25519_p1p1 tp1p1;
unsigned char w;
unsigned char sb[32];
sc25519_to32bytes(sb, s);
// Precomputation
pre[0] = g;
pre[1] = *p;
for(i=2;i<(1<<WINDOWSIZE);i+=2)
{
dbl_p1p1(&tp1p1, (ge25519_p2 *)(pre+i/2));
p1p1_to_p3(pre+i, &tp1p1);
add_p1p1(&tp1p1, pre+i, pre+1);
p1p1_to_p3(pre+i+1, &tp1p1);
}
// Fixed-window scalar multiplication
for(i=32;i>0;i--)
{
for(j=8-WINDOWSIZE;j>=0;j-=WINDOWSIZE)
{
for(k=0;k<WINDOWSIZE-1;k++)
{
dbl_p1p1(&tp1p1, (ge25519_p2 *)&g);
p1p1_to_p2((ge25519_p2 *)&g, &tp1p1);
}
dbl_p1p1(&tp1p1, (ge25519_p2 *)&g);
p1p1_to_p3(&g, &tp1p1);
// Cache-timing resistant loading of precomputed value:
w = (sb[i-1]>>j) & WINDOWMASK;
t = pre[0];
for(k=1;k<(1<<WINDOWSIZE);k++)
cmov_p3(&t, &pre[k], k==w);
add_p1p1(&tp1p1, &g, &t);
if(j != 0) p1p1_to_p2((ge25519_p2 *)&g, &tp1p1);
else p1p1_to_p3(&g, &tp1p1); /* convert to p3 representation at the end */
}
}
r->x = g.x;
r->y = g.y;
r->z = g.z;
r->t = g.t;
}
void ge25519_scalarmult_base(ge25519_p3 *r, const sc25519 *s)
{
/* XXX: Better algorithm for known-base-point scalar multiplication */
ge25519_p3 t;
fe25519_unpack(&t.x, ge25519_base_x);
fe25519_unpack(&t.y, ge25519_base_y);
fe25519_unpack(&t.z, ge25519_base_z);
fe25519_unpack(&t.t, ge25519_base_t);
ge25519_scalarmult(r, &t, s);
}

View File

@ -0,0 +1,34 @@
#ifndef GE25519_H
#define GE25519_H
#include "fe25519.h"
#include "sc25519.h"
#define ge25519 crypto_sign_edwards25519sha512batch_ge25519
#define ge25519_unpack_vartime crypto_sign_edwards25519sha512batch_ge25519_unpack_vartime
#define ge25519_pack crypto_sign_edwards25519sha512batch_ge25519_pack
#define ge25519_add crypto_sign_edwards25519sha512batch_ge25519_add
#define ge25519_double crypto_sign_edwards25519sha512batch_ge25519_double
#define ge25519_scalarmult crypto_sign_edwards25519sha512batch_ge25519_scalarmult
#define ge25519_scalarmult_base crypto_sign_edwards25519sha512batch_ge25519_scalarmult_base
typedef struct {
fe25519 x;
fe25519 y;
fe25519 z;
fe25519 t;
} ge25519;
int ge25519_unpack_vartime(ge25519 *r, const unsigned char p[32]);
void ge25519_pack(unsigned char r[32], const ge25519 *p);
void ge25519_add(ge25519 *r, const ge25519 *p, const ge25519 *q);
void ge25519_double(ge25519 *r, const ge25519 *p);
void ge25519_scalarmult(ge25519 *r, const ge25519 *p, const sc25519 *s);
void ge25519_scalarmult_base(ge25519 *r, const sc25519 *s);
#endif

View File

@ -0,0 +1,146 @@
#include "sc25519.h"
/*Arithmetic modulo the group order n = 2^252 + 27742317777372353535851937790883648493 = 7237005577332262213973186563042994240857116359379907606001950938285454250989 */
static const crypto_uint32 m[32] = {0xED, 0xD3, 0xF5, 0x5C, 0x1A, 0x63, 0x12, 0x58, 0xD6, 0x9C, 0xF7, 0xA2, 0xDE, 0xF9, 0xDE, 0x14,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
static const crypto_uint32 mu[33] = {0x1B, 0x13, 0x2C, 0x0A, 0xA3, 0xE5, 0x9C, 0xED, 0xA7, 0x29, 0x63, 0x08, 0x5D, 0x21, 0x06, 0x21,
0xEB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F};
/* Reduce coefficients of r before calling reduce_add_sub */
static void reduce_add_sub(sc25519 *r)
{
int i, b, pb=0, nb;
unsigned char t[32];
for(i=0;i<32;i++)
{
b = (r->v[i]<pb+m[i]);
t[i] = r->v[i]-pb-m[i]+b*256;
pb = b;
}
nb = 1-b;
for(i=0;i<32;i++)
r->v[i] = r->v[i]*b + t[i]*nb;
}
/* Reduce coefficients of x before calling barrett_reduce */
static void barrett_reduce(sc25519 *r, const crypto_uint32 x[64])
{
/* See HAC, Alg. 14.42 */
int i,j;
crypto_uint32 q2[66] = {0};
crypto_uint32 *q3 = q2 + 33;
crypto_uint32 r1[33];
crypto_uint32 r2[33] = {0};
crypto_uint32 carry;
int b, pb=0;
for(i=0;i<33;i++)
for(j=0;j<33;j++)
if(i+j >= 31) q2[i+j] += mu[i]*x[j+31];
carry = q2[31] >> 8;
q2[32] += carry;
carry = q2[32] >> 8;
q2[33] += carry;
for(i=0;i<33;i++)r1[i] = x[i];
for(i=0;i<32;i++)
for(j=0;j<33;j++)
if(i+j < 33) r2[i+j] += m[i]*q3[j];
for(i=0;i<32;i++)
{
carry = r2[i] >> 8;
r2[i+1] += carry;
r2[i] &= 0xff;
}
for(i=0;i<32;i++)
{
b = (r1[i]<pb+r2[i]);
r->v[i] = r1[i]-pb-r2[i]+b*256;
pb = b;
}
/* XXX: Can it really happen that r<0?, See HAC, Alg 14.42, Step 3
* If so: Handle it here!
*/
reduce_add_sub(r);
reduce_add_sub(r);
}
/*
static int iszero(const sc25519 *x)
{
// Implement
return 0;
}
*/
void sc25519_from32bytes(sc25519 *r, const unsigned char x[32])
{
int i;
crypto_uint32 t[64] = {0};
for(i=0;i<32;i++) t[i] = x[i];
barrett_reduce(r, t);
}
void sc25519_from64bytes(sc25519 *r, const unsigned char x[64])
{
int i;
crypto_uint32 t[64] = {0};
for(i=0;i<64;i++) t[i] = x[i];
barrett_reduce(r, t);
}
/* XXX: What we actually want for crypto_group is probably just something like
* void sc25519_frombytes(sc25519 *r, const unsigned char *x, size_t xlen)
*/
void sc25519_to32bytes(unsigned char r[32], const sc25519 *x)
{
int i;
for(i=0;i<32;i++) r[i] = x->v[i];
}
void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y)
{
int i, carry;
for(i=0;i<32;i++) r->v[i] = x->v[i] + y->v[i];
for(i=0;i<31;i++)
{
carry = r->v[i] >> 8;
r->v[i+1] += carry;
r->v[i] &= 0xff;
}
reduce_add_sub(r);
}
void sc25519_mul(sc25519 *r, const sc25519 *x, const sc25519 *y)
{
int i,j,carry;
crypto_uint32 t[64];
for(i=0;i<64;i++)t[i] = 0;
for(i=0;i<32;i++)
for(j=0;j<32;j++)
t[i+j] += x->v[i] * y->v[j];
/* Reduce coefficients */
for(i=0;i<63;i++)
{
carry = t[i] >> 8;
t[i+1] += carry;
t[i] &= 0xff;
}
barrett_reduce(r, t);
}
void sc25519_square(sc25519 *r, const sc25519 *x)
{
sc25519_mul(r, x, x);
}

View File

@ -0,0 +1,51 @@
#ifndef SC25519_H
#define SC25519_H
#define sc25519 crypto_sign_edwards25519sha512batch_sc25519
#define sc25519_from32bytes crypto_sign_edwards25519sha512batch_sc25519_from32bytes
#define sc25519_from64bytes crypto_sign_edwards25519sha512batch_sc25519_from64bytes
#define sc25519_to32bytes crypto_sign_edwards25519sha512batch_sc25519_to32bytes
#define sc25519_pack crypto_sign_edwards25519sha512batch_sc25519_pack
#define sc25519_getparity crypto_sign_edwards25519sha512batch_sc25519_getparity
#define sc25519_setone crypto_sign_edwards25519sha512batch_sc25519_setone
#define sc25519_setzero crypto_sign_edwards25519sha512batch_sc25519_setzero
#define sc25519_neg crypto_sign_edwards25519sha512batch_sc25519_neg
#define sc25519_add crypto_sign_edwards25519sha512batch_sc25519_add
#define sc25519_sub crypto_sign_edwards25519sha512batch_sc25519_sub
#define sc25519_mul crypto_sign_edwards25519sha512batch_sc25519_mul
#define sc25519_square crypto_sign_edwards25519sha512batch_sc25519_square
#define sc25519_invert crypto_sign_edwards25519sha512batch_sc25519_invert
#include "crypto_uint32.h"
typedef struct {
crypto_uint32 v[32];
} sc25519;
void sc25519_from32bytes(sc25519 *r, const unsigned char x[32]);
void sc25519_from64bytes(sc25519 *r, const unsigned char x[64]);
void sc25519_to32bytes(unsigned char r[32], const sc25519 *x);
void sc25519_pack(unsigned char r[32], const sc25519 *x);
unsigned char sc25519_getparity(const sc25519 *x);
void sc25519_setone(sc25519 *r);
void sc25519_setzero(sc25519 *r);
void sc25519_neg(sc25519 *r, const sc25519 *x);
void sc25519_add(sc25519 *r, const sc25519 *x, const sc25519 *y);
void sc25519_sub(sc25519 *r, const sc25519 *x, const sc25519 *y);
void sc25519_mul(sc25519 *r, const sc25519 *x, const sc25519 *y);
void sc25519_square(sc25519 *r, const sc25519 *x);
void sc25519_invert(sc25519 *r, const sc25519 *x);
#endif

View File

@ -0,0 +1,103 @@
#include "api.h"
#include "crypto_sign.h"
#include "crypto_hash_sha512.h"
#include "randombytes.h"
#include "crypto_verify_32.h"
#include "ge25519.h"
int crypto_sign_keypair(
unsigned char *pk,
unsigned char *sk
)
{
sc25519 scsk;
ge25519 gepk;
randombytes(sk, 32);
crypto_hash_sha512(sk, sk, 32);
sk[0] &= 248;
sk[31] &= 127;
sk[31] |= 64;
sc25519_from32bytes(&scsk,sk);
ge25519_scalarmult_base(&gepk, &scsk);
ge25519_pack(pk, &gepk);
return 0;
}
int crypto_sign(
unsigned char *sm,unsigned long long *smlen,
const unsigned char *m,unsigned long long mlen,
const unsigned char *sk
)
{
sc25519 sck, scs, scsk;
ge25519 ger;
unsigned char r[32];
unsigned char s[32];
unsigned long long i;
unsigned char hmg[crypto_hash_sha512_BYTES];
unsigned char hmr[crypto_hash_sha512_BYTES];
*smlen = mlen+64;
for(i=0;i<mlen;i++)
sm[32 + i] = m[i];
for(i=0;i<32;i++)
sm[i] = sk[32+i];
crypto_hash_sha512(hmg, sm, mlen+32); /* Generate k as h(m,sk[32],...,sk[63]) */
sc25519_from64bytes(&sck, hmg);
ge25519_scalarmult_base(&ger, &sck);
ge25519_pack(r, &ger);
for(i=0;i<32;i++)
sm[i] = r[i];
crypto_hash_sha512(hmr, sm, mlen+32); /* Compute h(m,r) */
sc25519_from64bytes(&scs, hmr);
sc25519_mul(&scs, &scs, &sck);
sc25519_from32bytes(&scsk, sk);
sc25519_add(&scs, &scs, &scsk);
sc25519_to32bytes(s,&scs); /* cat s */
for(i=0;i<32;i++)
sm[mlen+32+i] = s[i];
return 0;
}
int crypto_sign_open(
unsigned char *m,unsigned long long *mlen,
const unsigned char *sm,unsigned long long smlen,
const unsigned char *pk
)
{
int i;
unsigned char t1[32], t2[32];
ge25519 get1, get2, gepk;
sc25519 schmr, scs;
unsigned char hmr[crypto_hash_sha512_BYTES];
if (ge25519_unpack_vartime(&get1, sm)) return -1;
if (ge25519_unpack_vartime(&gepk, pk)) return -1;
crypto_hash_sha512(hmr,sm,smlen-32);
sc25519_from64bytes(&schmr, hmr);
ge25519_scalarmult(&get1, &get1, &schmr);
ge25519_add(&get1, &get1, &gepk);
ge25519_pack(t1, &get1);
sc25519_from32bytes(&scs, &sm[smlen-32]);
ge25519_scalarmult_base(&get2, &scs);
ge25519_pack(t2, &get2);
for(i=0;i<smlen-64;i++)
m[i] = sm[i + 32];
*mlen = smlen-64;
return crypto_verify_32(t1, t2);
}

View File

@ -0,0 +1,43 @@
#ifndef crypto_stream_salsa20_H
#define crypto_stream_salsa20_H
#define crypto_stream_salsa20_ref_KEYBYTES 32
#define crypto_stream_salsa20_ref_NONCEBYTES 8
#ifdef __cplusplus
#include <string>
extern std::string crypto_stream_salsa20_ref(size_t,const std::string &,const std::string &);
extern std::string crypto_stream_salsa20_ref_xor(const std::string &,const std::string &,const std::string &);
extern "C" {
#endif
extern int crypto_stream_salsa20_ref(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_salsa20_ref_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_salsa20_ref_beforenm(unsigned char *,const unsigned char *);
extern int crypto_stream_salsa20_ref_afternm(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_salsa20_ref_xor_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_stream_salsa20 crypto_stream_salsa20_ref
/* POTATO crypto_stream_salsa20_ref crypto_stream_salsa20_ref crypto_stream_salsa20 */
#define crypto_stream_salsa20_xor crypto_stream_salsa20_ref_xor
/* POTATO crypto_stream_salsa20_ref_xor crypto_stream_salsa20_ref crypto_stream_salsa20 */
#define crypto_stream_salsa20_beforenm crypto_stream_salsa20_ref_beforenm
/* POTATO crypto_stream_salsa20_ref_beforenm crypto_stream_salsa20_ref crypto_stream_salsa20 */
#define crypto_stream_salsa20_afternm crypto_stream_salsa20_ref_afternm
/* POTATO crypto_stream_salsa20_ref_afternm crypto_stream_salsa20_ref crypto_stream_salsa20 */
#define crypto_stream_salsa20_xor_afternm crypto_stream_salsa20_ref_xor_afternm
/* POTATO crypto_stream_salsa20_ref_xor_afternm crypto_stream_salsa20_ref crypto_stream_salsa20 */
#define crypto_stream_salsa20_KEYBYTES crypto_stream_salsa20_ref_KEYBYTES
/* POTATO crypto_stream_salsa20_ref_KEYBYTES crypto_stream_salsa20_ref crypto_stream_salsa20 */
#define crypto_stream_salsa20_NONCEBYTES crypto_stream_salsa20_ref_NONCEBYTES
/* POTATO crypto_stream_salsa20_ref_NONCEBYTES crypto_stream_salsa20_ref crypto_stream_salsa20 */
#define crypto_stream_salsa20_BEFORENMBYTES crypto_stream_salsa20_ref_BEFORENMBYTES
/* POTATO crypto_stream_salsa20_ref_BEFORENMBYTES crypto_stream_salsa20_ref crypto_stream_salsa20 */
#define crypto_stream_salsa20_IMPLEMENTATION "crypto_stream/salsa20/ref"
#ifndef crypto_stream_salsa20_ref_VERSION
#define crypto_stream_salsa20_ref_VERSION "-"
#endif
#define crypto_stream_salsa20_VERSION crypto_stream_salsa20_ref_VERSION
#endif

View File

@ -0,0 +1,43 @@
#ifndef crypto_stream_salsa2012_H
#define crypto_stream_salsa2012_H
#define crypto_stream_salsa2012_ref_KEYBYTES 32
#define crypto_stream_salsa2012_ref_NONCEBYTES 8
#ifdef __cplusplus
#include <string>
extern std::string crypto_stream_salsa2012_ref(size_t,const std::string &,const std::string &);
extern std::string crypto_stream_salsa2012_ref_xor(const std::string &,const std::string &,const std::string &);
extern "C" {
#endif
extern int crypto_stream_salsa2012_ref(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_salsa2012_ref_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_salsa2012_ref_beforenm(unsigned char *,const unsigned char *);
extern int crypto_stream_salsa2012_ref_afternm(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_salsa2012_ref_xor_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_stream_salsa2012 crypto_stream_salsa2012_ref
/* POTATO crypto_stream_salsa2012_ref crypto_stream_salsa2012_ref crypto_stream_salsa2012 */
#define crypto_stream_salsa2012_xor crypto_stream_salsa2012_ref_xor
/* POTATO crypto_stream_salsa2012_ref_xor crypto_stream_salsa2012_ref crypto_stream_salsa2012 */
#define crypto_stream_salsa2012_beforenm crypto_stream_salsa2012_ref_beforenm
/* POTATO crypto_stream_salsa2012_ref_beforenm crypto_stream_salsa2012_ref crypto_stream_salsa2012 */
#define crypto_stream_salsa2012_afternm crypto_stream_salsa2012_ref_afternm
/* POTATO crypto_stream_salsa2012_ref_afternm crypto_stream_salsa2012_ref crypto_stream_salsa2012 */
#define crypto_stream_salsa2012_xor_afternm crypto_stream_salsa2012_ref_xor_afternm
/* POTATO crypto_stream_salsa2012_ref_xor_afternm crypto_stream_salsa2012_ref crypto_stream_salsa2012 */
#define crypto_stream_salsa2012_KEYBYTES crypto_stream_salsa2012_ref_KEYBYTES
/* POTATO crypto_stream_salsa2012_ref_KEYBYTES crypto_stream_salsa2012_ref crypto_stream_salsa2012 */
#define crypto_stream_salsa2012_NONCEBYTES crypto_stream_salsa2012_ref_NONCEBYTES
/* POTATO crypto_stream_salsa2012_ref_NONCEBYTES crypto_stream_salsa2012_ref crypto_stream_salsa2012 */
#define crypto_stream_salsa2012_BEFORENMBYTES crypto_stream_salsa2012_ref_BEFORENMBYTES
/* POTATO crypto_stream_salsa2012_ref_BEFORENMBYTES crypto_stream_salsa2012_ref crypto_stream_salsa2012 */
#define crypto_stream_salsa2012_IMPLEMENTATION "crypto_stream/salsa2012/ref"
#ifndef crypto_stream_salsa2012_ref_VERSION
#define crypto_stream_salsa2012_ref_VERSION "-"
#endif
#define crypto_stream_salsa2012_VERSION crypto_stream_salsa2012_ref_VERSION
#endif

View File

@ -0,0 +1,2 @@
#define CRYPTO_KEYBYTES 32
#define CRYPTO_NONCEBYTES 8

View File

@ -0,0 +1,26 @@
#ifndef crypto_stream_H
#define crypto_stream_H
#include "crypto_stream_salsa2012.h"
#define crypto_stream crypto_stream_salsa2012
/* CHEESEBURGER crypto_stream_salsa2012 */
#define crypto_stream_xor crypto_stream_salsa2012_xor
/* CHEESEBURGER crypto_stream_salsa2012_xor */
#define crypto_stream_beforenm crypto_stream_salsa2012_beforenm
/* CHEESEBURGER crypto_stream_salsa2012_beforenm */
#define crypto_stream_afternm crypto_stream_salsa2012_afternm
/* CHEESEBURGER crypto_stream_salsa2012_afternm */
#define crypto_stream_xor_afternm crypto_stream_salsa2012_xor_afternm
/* CHEESEBURGER crypto_stream_salsa2012_xor_afternm */
#define crypto_stream_KEYBYTES crypto_stream_salsa2012_KEYBYTES
/* CHEESEBURGER crypto_stream_salsa2012_KEYBYTES */
#define crypto_stream_NONCEBYTES crypto_stream_salsa2012_NONCEBYTES
/* CHEESEBURGER crypto_stream_salsa2012_NONCEBYTES */
#define crypto_stream_BEFORENMBYTES crypto_stream_salsa2012_BEFORENMBYTES
/* CHEESEBURGER crypto_stream_salsa2012_BEFORENMBYTES */
#define crypto_stream_PRIMITIVE "salsa2012"
#define crypto_stream_IMPLEMENTATION crypto_stream_salsa2012_IMPLEMENTATION
#define crypto_stream_VERSION crypto_stream_salsa2012_VERSION
#endif

View File

@ -0,0 +1 @@
Daniel J. Bernstein

View File

@ -0,0 +1,49 @@
/*
version 20080913
D. J. Bernstein
Public domain.
*/
#include "crypto_core_salsa2012.h"
#include "crypto_stream.h"
typedef unsigned int uint32;
static const unsigned char sigma[16] = "expand 32-byte k";
int crypto_stream(
unsigned char *c,unsigned long long clen,
const unsigned char *n,
const unsigned char *k
)
{
unsigned char in[16];
unsigned char block[64];
int i;
unsigned int u;
if (!clen) return 0;
for (i = 0;i < 8;++i) in[i] = n[i];
for (i = 8;i < 16;++i) in[i] = 0;
while (clen >= 64) {
crypto_core_salsa2012(c,in,k,sigma);
u = 1;
for (i = 8;i < 16;++i) {
u += (unsigned int) in[i];
in[i] = u;
u >>= 8;
}
clen -= 64;
c += 64;
}
if (clen) {
crypto_core_salsa2012(block,in,k,sigma);
for (i = 0;i < clen;++i) c[i] = block[i];
}
return 0;
}

View File

@ -0,0 +1,52 @@
/*
version 20080913
D. J. Bernstein
Public domain.
*/
#include "crypto_core_salsa2012.h"
#include "crypto_stream.h"
typedef unsigned int uint32;
static const unsigned char sigma[16] = "expand 32-byte k";
int crypto_stream_xor(
unsigned char *c,
const unsigned char *m,unsigned long long mlen,
const unsigned char *n,
const unsigned char *k
)
{
unsigned char in[16];
unsigned char block[64];
int i;
unsigned int u;
if (!mlen) return 0;
for (i = 0;i < 8;++i) in[i] = n[i];
for (i = 8;i < 16;++i) in[i] = 0;
while (mlen >= 64) {
crypto_core_salsa2012(block,in,k,sigma);
for (i = 0;i < 64;++i) c[i] = m[i] ^ block[i];
u = 1;
for (i = 8;i < 16;++i) {
u += (unsigned int) in[i];
in[i] = u;
u >>= 8;
}
mlen -= 64;
c += 64;
m += 64;
}
if (mlen) {
crypto_core_salsa2012(block,in,k,sigma);
for (i = 0;i < mlen;++i) c[i] = m[i] ^ block[i];
}
return 0;
}

View File

@ -0,0 +1,43 @@
#ifndef crypto_stream_salsa208_H
#define crypto_stream_salsa208_H
#define crypto_stream_salsa208_ref_KEYBYTES 32
#define crypto_stream_salsa208_ref_NONCEBYTES 8
#ifdef __cplusplus
#include <string>
extern std::string crypto_stream_salsa208_ref(size_t,const std::string &,const std::string &);
extern std::string crypto_stream_salsa208_ref_xor(const std::string &,const std::string &,const std::string &);
extern "C" {
#endif
extern int crypto_stream_salsa208_ref(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_salsa208_ref_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_salsa208_ref_beforenm(unsigned char *,const unsigned char *);
extern int crypto_stream_salsa208_ref_afternm(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
extern int crypto_stream_salsa208_ref_xor_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
#ifdef __cplusplus
}
#endif
#define crypto_stream_salsa208 crypto_stream_salsa208_ref
/* POTATO crypto_stream_salsa208_ref crypto_stream_salsa208_ref crypto_stream_salsa208 */
#define crypto_stream_salsa208_xor crypto_stream_salsa208_ref_xor
/* POTATO crypto_stream_salsa208_ref_xor crypto_stream_salsa208_ref crypto_stream_salsa208 */
#define crypto_stream_salsa208_beforenm crypto_stream_salsa208_ref_beforenm
/* POTATO crypto_stream_salsa208_ref_beforenm crypto_stream_salsa208_ref crypto_stream_salsa208 */
#define crypto_stream_salsa208_afternm crypto_stream_salsa208_ref_afternm
/* POTATO crypto_stream_salsa208_ref_afternm crypto_stream_salsa208_ref crypto_stream_salsa208 */
#define crypto_stream_salsa208_xor_afternm crypto_stream_salsa208_ref_xor_afternm
/* POTATO crypto_stream_salsa208_ref_xor_afternm crypto_stream_salsa208_ref crypto_stream_salsa208 */
#define crypto_stream_salsa208_KEYBYTES crypto_stream_salsa208_ref_KEYBYTES
/* POTATO crypto_stream_salsa208_ref_KEYBYTES crypto_stream_salsa208_ref crypto_stream_salsa208 */
#define crypto_stream_salsa208_NONCEBYTES crypto_stream_salsa208_ref_NONCEBYTES
/* POTATO crypto_stream_salsa208_ref_NONCEBYTES crypto_stream_salsa208_ref crypto_stream_salsa208 */
#define crypto_stream_salsa208_BEFORENMBYTES crypto_stream_salsa208_ref_BEFORENMBYTES
/* POTATO crypto_stream_salsa208_ref_BEFORENMBYTES crypto_stream_salsa208_ref crypto_stream_salsa208 */
#define crypto_stream_salsa208_IMPLEMENTATION "crypto_stream/salsa208/ref"
#ifndef crypto_stream_salsa208_ref_VERSION
#define crypto_stream_salsa208_ref_VERSION "-"
#endif
#define crypto_stream_salsa208_VERSION crypto_stream_salsa208_ref_VERSION
#endif

View File

@ -0,0 +1,2 @@
#define CRYPTO_KEYBYTES 32
#define CRYPTO_NONCEBYTES 8

View File

@ -0,0 +1,26 @@
#ifndef crypto_stream_H
#define crypto_stream_H
#include "crypto_stream_salsa208.h"
#define crypto_stream crypto_stream_salsa208
/* CHEESEBURGER crypto_stream_salsa208 */
#define crypto_stream_xor crypto_stream_salsa208_xor
/* CHEESEBURGER crypto_stream_salsa208_xor */
#define crypto_stream_beforenm crypto_stream_salsa208_beforenm
/* CHEESEBURGER crypto_stream_salsa208_beforenm */
#define crypto_stream_afternm crypto_stream_salsa208_afternm
/* CHEESEBURGER crypto_stream_salsa208_afternm */
#define crypto_stream_xor_afternm crypto_stream_salsa208_xor_afternm
/* CHEESEBURGER crypto_stream_salsa208_xor_afternm */
#define crypto_stream_KEYBYTES crypto_stream_salsa208_KEYBYTES
/* CHEESEBURGER crypto_stream_salsa208_KEYBYTES */
#define crypto_stream_NONCEBYTES crypto_stream_salsa208_NONCEBYTES
/* CHEESEBURGER crypto_stream_salsa208_NONCEBYTES */
#define crypto_stream_BEFORENMBYTES crypto_stream_salsa208_BEFORENMBYTES
/* CHEESEBURGER crypto_stream_salsa208_BEFORENMBYTES */
#define crypto_stream_PRIMITIVE "salsa208"
#define crypto_stream_IMPLEMENTATION crypto_stream_salsa208_IMPLEMENTATION
#define crypto_stream_VERSION crypto_stream_salsa208_VERSION
#endif

Some files were not shown because too many files have changed in this diff Show More