TaoCrypt provides ARC4 for stream cipher needs. Like BlockCipher, ARC4 can be
used with just two functions:
void SetKey(const byte*, word32);
void Process(byte*, const byte*, word32);
Typdefs are also provided in the header for encryption and decryption needs.
Here is a simple example that encrypts:
byte key[16] = { // some key };
byte buffer[100] = { // some plain text };
byte cipherText[100];
ARC4::Encryption enc;
enc.SetKey(key, 16);
enc.Process(cipherText, buffer, 100);
Decrypting is analogous:
byte plainText[100];
ARC4::Decryption dec;
dec.SetKey(key, 16);
dec.Process(plainText, cipherText, 100);
Please see test.cpp for a complete example and test vectors.
TaoCrypt provides RSA and DSA for Public Key Cryptography.
RSA
There are public and private RSA keys, RSA_PublicKey and
RSA_PrivateKey. Typically, they are initialized with a Source
object, which is usually constructed with a byte array or a file:
byte privKey[64] = { // some key };
Source privSrc(privKey, 64);
RSA_PrivateKey rsaPriv(privSrc);
A public key can also be constructed from a private key:
RSA_PublicKey rsaPub(rsaPriv);
// or a file source example
Source fSrc;
FileSource("./rsaPublic.dat", fSrc);
RSA_PublicKey rsaPub(fSrc);
Once you have a public key, you can perform public encryption:
byte buffer[64] = { // plain Text };
byte cipher[64];
RandomNumberGenerator rng;
RSAES_Encryptor enc(rsaPub);
enc.Encrypt(buffer, 64, cipher, rng);
RSAES_Encryptor is a typedef for:
typedef RSA_Encryptor<> RSAES_Encryptor;
Where the default template argument is RSA_BlockType2, a
padding scheme. Decrypting requires a private key:
byte plain[64];
RSAES_Decryptor dec(rsaPriv);
dec.Decrypt(cipher, 64, plain, rng);
TaoCrypt can also do RSA sign and verify operations, including the SSL type
which require RSA_BlockType1 padding. The member functions SSL_Sign()
and SSL_Verify() handle these and are used with the same arguments as
encryption and decryption. TaoCrypt handles inversing the keys transparently.
Please see test.cpp for a complete example.
DSA
There are public and private DSA keys, DSA_PublicKey and
DSA_PrivateKey. Typically, they are initialized with a Source
object, which is usually constructed with a byte array or a file:
byte privKey[128] = { // some key };
Source privSrc(privKey, 128);
DSA_PrivateKey dsaPriv(privSrc);
Once you have a private DSA key, you can sign a message, usually an SHA digest:
RandomNumberGenerator rng;
byte message[SHA::DIGEST_SIZE] = { // a hash };
byte signature[40];
DSA_Signer signer(dsaPriv);
signer.Sign(message, signature, rng);
Verifying is a simple operation as well:
DSA_Verifier verifier(dsaPriv); // or Public Key
bool result = verifier.Verify(message, signautre);
Please see test.cpp for a complete example.
TaoCrypt provides Diffie-Hellman (DH) for key agreement arrangements.
The DH class is generally constructed from a Source object to initialize
p and g.
byte key[80] = { // contains p and g };
Source keySrc(key, 80);
DH self(keySrc);
Once you have a DH object, you generate a key pair:
byte pub[128];
byte priv[128];
RandomNumberGenerator rng;
self.GenerateKeyPair(rng, priv, pub);
Then you can send someone your public key and obtain their public one. Using
your private key and their public key you can generate an agreement:
byte agree[128];
self.Agree(agree, priv, otherPublicKey);
The other person will get the same agreement. Please see test.cpp for a
complete example.