#define M26 0x03ffffffu
#define M25 0x01ffffffu
-#define B26 0x04000000u
#define B25 0x02000000u
#define B24 0x01000000u
((i) == 5 || (i) == 10 || (i) == 15 || (i) == 20 || (i) == 25 ? 9 : 10)
#define NPIECE 26
-#define B10 0x0400
-#define B9 0x200
-#define B8 0x100
#define M10 0x3ff
#define M9 0x1ff
+#define B9 0x200
+#define B8 0x100
#endif
#define NPIECE 16
#define P p28
-#define B28 0x10000000u
#define B27 0x08000000u
#define M28 0x0fffffffu
-#define M27 0x07ffffffu
#define M32 0xffffffffu
#elif FGOLDI_IMPL == 12
#define NPIECE 40
#define P p12
-#define B12 0x1000u
#define B11 0x0800u
#define B10 0x0400u
#define M12 0xfffu
#define M11 0x7ffu
-#define M10 0x3ffu
#define M8 0xffu
#endif
/*----- ChaCha implementation ---------------------------------------------*/
+static const octet zerononce[XCHACHA_NONCESZ];
+
/* --- @chacha_init@ --- *
*
* Arguments: @chacha_ctx *ctx@ = context to fill in
void chacha_init(chacha_ctx *ctx, const void *key, size_t ksz,
const void *nonce)
{
- static const octet zerononce[CHACHA_NONCESZ];
-
populate(ctx->a, key, ksz);
chacha_setnonce(ctx, nonce ? nonce : zerononce);
}
void XCHACHA_INIT(r, XCHACHA_CTX(r) *ctx, \
const void *key, size_t ksz, const void *nonce) \
{ \
- static const octet zerononce[XCHACHA_NONCESZ]; \
- \
populate(ctx->k, key, ksz); \
ctx->s.a[ 0] = CHACHA_A256; \
ctx->s.a[ 1] = CHACHA_B256; \
\
const gccipher xchacha##r = { \
"xchacha" #r, chacha_keysz, \
- CHACHA_NONCESZ, gxinit_##r \
+ XCHACHA_NONCESZ, gxinit_##r \
};
CHACHA_VARS(DEFGXCIPHER)
/*----- Salsa20 implementation --------------------------------------------*/
+static const octet zerononce[XSALSA20_NONCESZ];
+
/* --- @salsa20_init@ --- *
*
* Arguments: @salsa20_ctx *ctx@ = context to fill in
void salsa20_init(salsa20_ctx *ctx, const void *key, size_t ksz,
const void *nonce)
{
- static const octet zerononce[SALSA20_NONCESZ];
-
populate(ctx->a, key, ksz);
salsa20_setnonce(ctx, nonce ? nonce : zerononce);
}
void XSALSA20_INIT(r, XSALSA20_CTX(r) *ctx, \
const void *key, size_t ksz, const void *nonce) \
{ \
- static const octet zerononce[XSALSA20_NONCESZ]; \
- \
populate(ctx->k, key, ksz); \
ctx->s.a[ 0] = SALSA20_A256; \
ctx->s.a[ 1] = SALSA20_B256; \
xchacha20 {
## Unfortunately, XChaCha isn't actually defined anywhere, even though it's
- ## obvious how to do it. These test vectors are from
- ## https://github.com/DaGenix/rust-crypto/blob/master/src/chacha20.rs
+ ## obvious how to do it.
+ ## These test vectors are from
+ ## https://github.com/DaGenix/rust-crypto/blob/master/src/chacha20.rs
1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389
69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37 "" 0 ""
4febf2fe4b359c508dc5e8b5980c88e38946d8f18f313465c862a08782648248018dacdcb904178853a46dca3a0eaaee747cba97434eaffad58fea8222047e0de6c3a6775106e0331ad714d2f27a55641340a1f1dd9f94532e68cb241cbdd150970d14e05c5b173193fb14f51c41f393835bf7f416a7e0bba81ffb8b13af0e21691d7ecec93b75e6e4183a;
+
+ ## This one's from draft-irtf-cfrg-xchacha-03.
+ 808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f
+ 404142434445464748494a4b4c4d4e4f5051525354555658 "" 64
+ 5468652064686f6c65202870726f6e6f756e6365642022646f6c65222920697320616c736f206b6e6f776e2061732074686520417369617469632077696c6420646f672c2072656420646f672c20616e642077686973746c696e6720646f672e2049742069732061626f7574207468652073697a65206f662061204765726d616e20736865706865726420627574206c6f6f6b73206d6f7265206c696b652061206c6f6e672d6c656767656420666f782e205468697320686967686c7920656c757369766520616e6420736b696c6c6564206a756d70657220697320636c6173736966696564207769746820776f6c7665732c20636f796f7465732c206a61636b616c732c20616e6420666f78657320696e20746865207461786f6e6f6d69632066616d696c792043616e696461652e
+ 7d0a2e6b7f7c65a236542630294e063b7ab9b555a5d5149aa21e4ae1e4fbce87ecc8e08a8b5e350abe622b2ffa617b202cfad72032a3037e76ffdcdc4376ee053a190d7e46ca1de04144850381b9cb29f051915386b8a710b8ac4d027b8b050f7cba5854e028d564e453b8a968824173fc16488b8970cac828f11ae53cabd20112f87107df24ee6183d2274fe4c8b1485534ef2c5fbc1ec24bfc3663efaa08bc047d29d25043532db8391a8a3d776bf4372a6955827ccb0cdd4af403a7ce4c63d595c75a43e045f0cce1f29c8b93bd65afc5974922f214a40b7c402cdb91ae73c0b63615cdad0480680f16515a7ace9d39236464328a37743ffc28f4ddb324f4d0f5bbdc270c65b1749a6efff1fbaa09536175ccd29fb9e6057b307320d316838a9c71f70b5b5907a66f7ea49aadc409;
}
chacha8 {