Commit 5311f248 authored by Herbert Xu's avatar Herbert Xu

[CRYPTO] ctr: Refactor into ctr and rfc3686

As discussed previously, this patch moves the basic CTR functionality
into a chainable algorithm called ctr.  The IPsec-specific variant of
it is now placed on top with the name rfc3686.

So ctr(aes) gives a chainable cipher with IV size 16 while the IPsec
variant will be called rfc3686(ctr(aes)).  This patch also adjusts
gcm accordingly.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 653ebd9c
This diff is collapsed.
......@@ -160,7 +160,7 @@ static void crypto_gcm_ghash_final_xor(struct crypto_gcm_ghash_ctx *ctx,
static inline void crypto_gcm_set_counter(u8 *counterblock, u32 value)
{
*((u32 *)&counterblock[12]) = cpu_to_be32(value);
*((u32 *)&counterblock[12]) = cpu_to_be32(value + 1);
}
static int crypto_gcm_encrypt_counter(struct crypto_aead *aead, u8 *block,
......@@ -400,9 +400,8 @@ static struct crypto_instance *crypto_gcm_alloc(struct rtattr **tb)
return inst;
inst = ERR_PTR(ENAMETOOLONG);
if (snprintf(
ctr_name, CRYPTO_MAX_ALG_NAME,
"ctr(%s,0,16,4)", cipher->cra_name) >= CRYPTO_MAX_ALG_NAME)
if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)",
cipher->cra_name) >= CRYPTO_MAX_ALG_NAME)
return inst;
ctr = crypto_alg_mod_lookup(ctr_name, CRYPTO_ALG_TYPE_BLKCIPHER,
......
......@@ -1193,9 +1193,9 @@ static void do_test(void)
AES_XTS_ENC_TEST_VECTORS);
test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
AES_XTS_DEC_TEST_VECTORS);
test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
AES_CTR_ENC_TEST_VECTORS);
test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
AES_CTR_DEC_TEST_VECTORS);
test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
AES_GCM_ENC_TEST_VECTORS);
......@@ -1394,9 +1394,9 @@ static void do_test(void)
AES_XTS_ENC_TEST_VECTORS);
test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
AES_XTS_DEC_TEST_VECTORS);
test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
AES_CTR_ENC_TEST_VECTORS);
test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
AES_CTR_DEC_TEST_VECTORS);
break;
......
/*
* CTR: Counter mode
*
* Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*/
#ifndef _CRYPTO_CTR_H
#define _CRYPTO_CTR_H
#define CTR_RFC3686_NONCE_SIZE 4
#define CTR_RFC3686_IV_SIZE 8
#define CTR_RFC3686_BLOCK_SIZE 16
#endif /* _CRYPTO_CTR_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment