diff options
author | Joy Latten <latten@austin.ibm.com> | 2007-10-22 20:50:32 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-01-10 16:16:01 -0500 |
commit | 23e353c8a681cc30d42fbd4f2c2be85c44fe209b (patch) | |
tree | d64934fa42e3e1e2b3fcccb4e86168a1614e250d /crypto/tcrypt.c | |
parent | 490fe3f05be3f7c87d7932bcb6e6e53e3db2cd9c (diff) |
[CRYPTO] ctr: Add CTR (Counter) block cipher mode
This patch implements CTR mode for IPsec.
It is based off of RFC 3686.
Please note:
1. CTR turns a block cipher into a stream cipher.
Encryption is done in blocks, however the last block
may be a partial block.
A "counter block" is encrypted, creating a keystream
that is xor'ed with the plaintext. The counter portion
of the counter block is incremented after each block
of plaintext is encrypted.
Decryption is performed in same manner.
2. The CTR counterblock is composed of,
nonce + IV + counter
The size of the counterblock is equivalent to the
blocksize of the cipher.
sizeof(nonce) + sizeof(IV) + sizeof(counter) = blocksize
The CTR template requires the name of the cipher
algorithm, the sizeof the nonce, and the sizeof the iv.
ctr(cipher,sizeof_nonce,sizeof_iv)
So for example,
ctr(aes,4,8)
specifies the counterblock will be composed of 4 bytes
from a nonce, 8 bytes from the iv, and 4 bytes for counter
since aes has a blocksize of 16 bytes.
3. The counter portion of the counter block is stored
in big endian for conformance to rfc 3686.
Signed-off-by: Joy Latten <latten@austin.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r-- | crypto/tcrypt.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c index 24141fb6f5cb..640cbcad32a1 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -969,6 +969,10 @@ static void do_test(void) | |||
969 | AES_XTS_ENC_TEST_VECTORS); | 969 | AES_XTS_ENC_TEST_VECTORS); |
970 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, | 970 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, |
971 | AES_XTS_DEC_TEST_VECTORS); | 971 | AES_XTS_DEC_TEST_VECTORS); |
972 | test_cipher("ctr(aes,4,8)", ENCRYPT, aes_ctr_enc_tv_template, | ||
973 | AES_CTR_ENC_TEST_VECTORS); | ||
974 | test_cipher("ctr(aes,4,8)", DECRYPT, aes_ctr_dec_tv_template, | ||
975 | AES_CTR_DEC_TEST_VECTORS); | ||
972 | 976 | ||
973 | //CAST5 | 977 | //CAST5 |
974 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, | 978 | test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template, |
@@ -1156,6 +1160,10 @@ static void do_test(void) | |||
1156 | AES_XTS_ENC_TEST_VECTORS); | 1160 | AES_XTS_ENC_TEST_VECTORS); |
1157 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, | 1161 | test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template, |
1158 | AES_XTS_DEC_TEST_VECTORS); | 1162 | AES_XTS_DEC_TEST_VECTORS); |
1163 | test_cipher("ctr(aes,4,8)", ENCRYPT, aes_ctr_enc_tv_template, | ||
1164 | AES_CTR_ENC_TEST_VECTORS); | ||
1165 | test_cipher("ctr(aes,4,8)", DECRYPT, aes_ctr_dec_tv_template, | ||
1166 | AES_CTR_DEC_TEST_VECTORS); | ||
1159 | break; | 1167 | break; |
1160 | 1168 | ||
1161 | case 11: | 1169 | case 11: |