Skip to content

Commit

Permalink
add Salsa20 cipher
Browse files Browse the repository at this point in the history
  • Loading branch information
weidai11 committed Dec 9, 2006
1 parent d5a0764 commit 28c392e
Show file tree
Hide file tree
Showing 15 changed files with 437 additions and 186 deletions.
5 changes: 4 additions & 1 deletion Readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Crypto++: a C++ Class Library of Cryptographic Schemes
Version 5.3 (in development)
Version 5.4 (in development)

This library includes:

Expand Down Expand Up @@ -354,4 +354,7 @@ the mailing list.
- Added defense against AES timing attacks, and more AES test vectors
- Changed StaticAlgorithmName() of Rijndael to "AES", CTR to "CTR"

5.4 - added Salsa20
- updated Whirlpool to version 3.0

Written by Wei Dai
1 change: 1 addition & 0 deletions TestVectors/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Plaintext - encoded string
Ciphertext - encoded string
Digest - encoded string
TruncatedSize - int, size of truncated digest in bytes
Seek - int, seek location for random access ciphers
(more to come here)

Possible Tests
Expand Down
1 change: 1 addition & 0 deletions TestVectors/all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ Test: seal.txt
Test: sha.txt
Test: panama.txt
Test: aes.txt
Test: salsa.txt
33 changes: 33 additions & 0 deletions TestVectors/salsa.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
AlgorithmType: SymmetricCipher
Name: Salsa20
Source: http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/full/verified.test-vectors?rev=161&view=markup
Comment: Set 1, vector# 0
Key: 80000000000000000000000000000000
IV: 0000000000000000
Plaintext: r16 00000000
Seek: 0
Ciphertext: 4DFA5E481DA23EA09A31022050859936DA52FCEE218005164F267CB65F5CFD7F2B4F97E0FF16924A52DF269515110A07F9E460BC65EF95DA58F740B7D1DBB0AA
Test: Encrypt
Seek: 448
Ciphertext: B375703739DACED4DD4059FD71C3C47FC2F9939670FAD4A46066ADCC6A5645783308B90FFB72BE04A6B147CBE38CC0C3B9267C296A92A7C69873F9F263BE9703
Test: Encrypt
Seek: 192
Plaintext: r32 00000000
Ciphertext: DA9C1581F429E0A00F7D67E23B730676783B262E8EB43A25F55FB90B3E753AEF8C6713EC66C51881111593CCB3E8CB8F8DE124080501EEEB389C4BCB6977CF95\
7D5789631EB4554400E1E025935DFA7B3E9039D61BDC58A8697D36815BF1985CEFDF7AE112E5BB81E37ECF0616CE7147FC08A93A367E08631F23C03B00A8DA2F
Test: Encrypt
Comment: Set 3, vector#243
Key: F3F4F5F6F7F8F9FAFBFCFDFEFF000102030405060708090A0B0C0D0E0F101112
IV: 0000000000000000
Plaintext: r16 00000000
Seek: 0
Ciphertext: B4C0AFA503BE7FC29A62058166D56F8F5D27DC246F75B9AD8760C8C39DFD87492D3B76D5D9637F009EADA14458A52DFB09815337E72672681DDDC24633750D83
Test: Encrypt
Seek: 448
Ciphertext: 5A5FB5C8F0AFEA471F0318A4A2792F7AA5C67B6D6E0F0DDB79961C34E3A564BA2EECE78D9AFF45E510FEAB1030B102D39DFCECB77F5798F7D2793C0AB09C7A04
Test: Encrypt
Seek: 192
Plaintext: r32 00000000
Ciphertext: DBBA0683DF48C335A9802EEF0252256354C9F763C3FDE19131A6BB7B85040624B1D6CD4BF66D16F7482236C8602A6D58505EEDCCA0B77AED574AB583115124B9\
F0C5F98BAE05E019764EF6B65E0694A904CB9EC9C10C297B1AB1A6052365BB78E55D3C6CB9F06184BA7D425A92E7E987757FC5D9AFD7082418DD64125CA6F2B6
Test: Encrypt
13 changes: 9 additions & 4 deletions bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "mdc.h"
#include "lubyrack.h"
#include "tea.h"
#include "salsa.h"

#include <time.h>
#include <math.h>
Expand Down Expand Up @@ -184,19 +185,19 @@ void BenchMark(const char *name, BufferedTransformation &bt, double timeTotal)

//VC60 workaround: compiler bug triggered without the extra dummy parameters
template <class T>
void BenchMarkKeyed(const char *name, double timeTotal, T *x=NULL)
void BenchMarkKeyed(const char *name, double timeTotal, const NameValuePairs &params = g_nullNameValuePairs, T *x=NULL)
{
T c;
c.SetKey(key, c.DefaultKeyLength(), MakeParameters(Name::IV(), key, false));
c.SetKey(key, c.DefaultKeyLength(), CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false)));
BenchMark(name, c, timeTotal);
}

//VC60 workaround: compiler bug triggered without the extra dummy parameters
template <class T>
void BenchMarkKeyedVariable(const char *name, double timeTotal, unsigned int keyLength, T *x=NULL)
void BenchMarkKeyedVariable(const char *name, double timeTotal, unsigned int keyLength, const NameValuePairs &params = g_nullNameValuePairs, T *x=NULL)
{
T c;
c.SetKey(key, keyLength, MakeParameters(Name::IV(), key, false));
c.SetKey(key, keyLength, CombinedNameValuePairs(params, MakeParameters(Name::IV(), key, false)));
BenchMark(name, c, timeTotal);
}

Expand Down Expand Up @@ -287,6 +288,10 @@ void BenchmarkAll(double t)
BenchMarkKeyedVariable<Camellia::Encryption>("Camellia (128-bit key)", t, 16);
BenchMarkKeyedVariable<Camellia::Encryption>("Camellia (256-bit key)", t, 32);
#endif
BenchMarkKeyed<Salsa20::Encryption>("Salsa20", t);
BenchMarkKeyed<Salsa20::Encryption>("Salsa20/12", t, MakeParameters(Name::Rounds(), 12));
BenchMarkKeyed<Salsa20::Encryption>("Salsa20/8", t, MakeParameters(Name::Rounds(), 8));

BenchMarkKeyed<MD5MAC>("MD5-MAC", t);
BenchMarkKeyed<XMACC<MD5> >("XMACC/MD5", t);
BenchMarkKeyed<HMAC<MD5> >("HMAC/MD5", t);
Expand Down
Loading

0 comments on commit 28c392e

Please sign in to comment.