From: karthikbalaguru on
Hi,

AES Counter mode (AES-CTR) is discussed in RFC 3686,
But, i am unable to find a sample source code just as in
AES CMAC discussion in RFC 4493.
Is there any similar references for AES CTR ?
Can anyone provide me with a link for an opensource
implementation of AES CTR?

Thx in advans,
Karthik Balaguru
From: amzoti on
On Oct 6, 10:11 am, karthikbalaguru <karthikbalagur...(a)gmail.com>
wrote:
> Hi,
>
> AES Counter mode (AES-CTR) is discussed in RFC 3686,
> But, i am unable to find a sample source code just as in
> AES CMAC discussion in RFC 4493.
> Is there any similar references for AES CTR ?
> Can anyone provide me with a link for an opensource
> implementation of AES CTR?
>
> Thx in advans,
> Karthik Balaguru

Did you try crypto++, libtomcrypt, or http://fp.gladman.plus.com/AES/index.htm
(Brian Gladman).

I am sure there are many others.

HTH ~A
From: Joseph Ashwood on

"karthikbalaguru" <karthikbalaguru79(a)gmail.com> wrote in message
news:50af9463-2a2f-4703-be99-2fd7d74461d8(a)z6g2000pre.googlegroups.com...
> Hi,
>
> AES Counter mode (AES-CTR) is discussed in RFC 3686,
> But, i am unable to find a sample source code just as in
> AES CMAC discussion in RFC 4493.
> Is there any similar references for AES CTR ?
> Can anyone provide me with a link for an opensource
> implementation of AES CTR?


I don't know what language you are working in, but the pseudo-code itself is
rather trivial:
//Block is typically byte[16]

Fixed:
KEY = key value, commonly implemented as a prescheduled key
Persistent:
Block CTR = IV //initial counter value, typically 0, treatable as an
integer, look to type conversions



Block Encrypt_Block(Block plaintext) {
Block ciphertext;
ciphertext = AES_Encrypt_Block(KEY,IV) XOR plaintext;
IV = IV+1;
return ciphertext;
}

Block Decrypt_Block(Block ciphertext){
Block plaintext;
plaintext = AES_Encrypt_Block(KEY, IV) XOR ciphertext;
IV = IV+1;
return plaintext;
}

Assuming I didn't do anything stupid, and don't have any typos, that should
be easily translated to any programming language.
Joe

From: Blind Anagram on
"karthikbalaguru" <karthikbalaguru79(a)gmail.com> wrote in message
news:50af9463-2a2f-4703-be99-2fd7d74461d8(a)z6g2000pre.googlegroups.com...
> Hi,
>
> AES Counter mode (AES-CTR) is discussed in RFC 3686,
> But, i am unable to find a sample source code just as in
> AES CMAC discussion in RFC 4493.

CMAC is the same as OMAC version 1, for which you should be able to find
several implementations

> Is there any similar references for AES CTR ?
> Can anyone provide me with a link for an opensource
> implementation of AES CTR?

In terms of my own CTR mode implementation, the code for
RFC3686 in C is:

#include <string.h>
#include "aes.h"

void rfc3686_inc(unsigned char ctr_buf[AES_BLOCK_SIZE])
{
if(!(++(ctr_buf[15])))
if(!(++(ctr_buf[14])))
if(!(++(ctr_buf[13])))
++(ctr_buf[12]);
}

void rfc3686_init( unsigned char none[4],
unsigned char iv[8],
unsigned char ctr_buf[AES_BLOCK_SIZE])
{
memcpy(ctr_buf, nonce, 4);
memcpy(ctr_buf + 4, iv, 8);
memset(ctr_buf + 12, 0, 4);
rfc3686_inc(ctr_buf);
}

AES_RETURN rfc3686_crypt(const unsigned char *ibuf,
unsigned char *obuf, unsigned int len,
unsigned char *cbuf, aes_encrypt_ctx cx[1])
{
return aes_ctr_crypt(ibuf, obuf, len, cbuf, rfc3686_inc, cx);
}

/* example use (not tested) */
void do_crypt(const unsigned char *ibuf, unsigned char *obuf,
unsigned int len, unsigned char *key, int key_len
unsighed char nonce[4], unsigned char iv[8])
{ aes_encrypt_ctx aes_ctx[1];
unsigned char ctr_buf[AES_BLOCK_SIZE];
aes_encrypt_key(key, key_len, aes_ctx);
rfc3686_init(nonce, iv, ctr_buf);
rfc3686_crypt(ibuf, obuf, len, ctr_buf, aes_ctx);
}

Extra code will be needed in production for clearing sensitive buffers etc.

Brian Gladman

 | 
Pages: 1
Prev: Merry Christmas 7
Next: Cipher challenge