[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Add a the public-domain AES implementation, with a minimal ...



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv3613/src/common

Added Files:
	aes.c aes.h 
Log Message:
Add a the public-domain AES implementation, with a minimal counter-mode wrapper.

--- NEW FILE: aes.c ---
/* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
/* See LICENSE for licensing information */
/* $Id: aes.c,v 1.1 2003/06/30 19:18:12 nickm Exp $ */

/* Implementation of a simple AES counter mode.  We include AES because
 *   1) it didn't come with any versions of OpenSSL before 0.9.7.
 * We include counter mode because OpenSSL doesn't do it right.
 */

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "../../orconfig.h"
#include "./aes.h"
#include "util.h"

/*======================================================================*/
/* From rijndael-alg-fst.h */
[...1317 lines suppressed...]
   		(Td4[(t3 >>  8) & 0xff] & 0x0000ff00) ^
   		(Td4[(t2      ) & 0xff] & 0x000000ff) ^
   		rk[1];
	PUTU32(pt +  4, s1);
   	s2 =
   		(Td4[(t2 >> 24)       ] & 0xff000000) ^
   		(Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
   		(Td4[(t0 >>  8) & 0xff] & 0x0000ff00) ^
   		(Td4[(t3      ) & 0xff] & 0x000000ff) ^
   		rk[2];
	PUTU32(pt +  8, s2);
   	s3 =
   		(Td4[(t3 >> 24)       ] & 0xff000000) ^
   		(Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
   		(Td4[(t1 >>  8) & 0xff] & 0x0000ff00) ^
   		(Td4[(t0      ) & 0xff] & 0x000000ff) ^
   		rk[3];
	PUTU32(pt + 12, s3);
}
#endif

--- NEW FILE: aes.h ---
/* Copyright 2003 Roger Dingledine */
/* See LICENSE for licensing information */
/* $Id: aes.h,v 1.1 2003/06/30 19:18:12 nickm Exp $ */

/* Implements a minimal interface to counter-mode AES. */

#ifndef __AES_H
#define __AES_H

#include <stdint.h>

struct aes_cnt_cipher;
typedef struct aes_cnt_cipher aes_cnt_cipher_t;

aes_cnt_cipher_t* aes_new_cipher();
void aes_free_cipher(aes_cnt_cipher_t *cipher);
void aes_set_key(aes_cnt_cipher_t *cipher, unsigned char *key, int key_bits);
void aes_crypt(aes_cnt_cipher_t *cipher, char *input, int len, char *output);
uint64_t aes_get_counter(aes_cnt_cipher_t *cipher);
void aes_set_counter(aes_cnt_cipher_t *cipher, uint64_t counter);
void aes_adjust_counter(aes_cnt_cipher_t *cipher, long delta);

#endif