~ubuntu-branches/ubuntu/hardy/openswan/hardy-updates

« back to all changes in this revision

Viewing changes to linux/include/crypto/aes.h

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2005-01-27 16:10:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050127161011-idgybmyz3vwhpfiq
Tags: 2.3.0-2
Urgency HIGH due to security issue and problems with build-deps in sarge.
* Fix the security issue. Please see
  http://www.idefense.com/application/poi/display?id=190&
      type=vulnerabilities&flashstatus=false
  for more details. Thanks to Martin Schulze for informing me about
  this issue.
  Closes: #292458: Openswan XAUTH/PAM Buffer Overflow Vulnerability
* Added a Build-Dependency to lynx.
  Closes: #291143: openswan: FTBFS: Missing build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// I retain copyright in this code but I encourage its free use provided
 
2
// that I don't carry any responsibility for the results. I am especially 
 
3
// happy to see it used in free and open source software. If you do use 
 
4
// it I would appreciate an acknowledgement of its origin in the code or
 
5
// the product that results and I would also appreciate knowing a little
 
6
// about the use to which it is being put. I am grateful to Frank Yellin
 
7
// for some ideas that are used in this implementation.
 
8
//
 
9
// Dr B. R. Gladman <brg@gladman.uk.net> 6th April 2001.
 
10
//
 
11
// This is an implementation of the AES encryption algorithm (Rijndael)
 
12
// designed by Joan Daemen and Vincent Rijmen. This version is designed
 
13
// to provide both fixed and dynamic block and key lengths and can also 
 
14
// run with either big or little endian internal byte order (see aes.h). 
 
15
// It inputs block and key lengths in bytes with the legal values being 
 
16
// 16, 24 and 32.
 
17
 
 
18
/*
 
19
 * Modified by Jari Ruusu,  May 1 2001
 
20
 *  - Fixed some compile warnings, code was ok but gcc warned anyway.
 
21
 *  - Changed basic types: byte -> unsigned char, word -> u_int32_t
 
22
 *  - Major name space cleanup: Names visible to outside now begin
 
23
 *    with "aes_" or "AES_". A lot of stuff moved from aes.h to aes.c
 
24
 *  - Removed C++ and DLL support as part of name space cleanup.
 
25
 *  - Eliminated unnecessary recomputation of tables. (actual bug fix)
 
26
 *  - Merged precomputed constant tables to aes.c file.
 
27
 *  - Removed data alignment restrictions for portability reasons.
 
28
 *  - Made block and key lengths accept bit count (128/192/256)
 
29
 *    as well byte count (16/24/32).
 
30
 *  - Removed all error checks. This change also eliminated the need
 
31
 *    to preinitialize the context struct to zero.
 
32
 *  - Removed some totally unused constants.
 
33
 */
 
34
 
 
35
#ifndef _AES_H
 
36
#define _AES_H
 
37
 
 
38
#if defined(__linux__) && defined(__KERNEL__)
 
39
#  include <linux/types.h>
 
40
#else 
 
41
#  include <sys/types.h>
 
42
#endif
 
43
 
 
44
// CONFIGURATION OPTIONS (see also aes.c)
 
45
//
 
46
// Define AES_BLOCK_SIZE to set the cipher block size (16, 24 or 32) or
 
47
// leave this undefined for dynamically variable block size (this will
 
48
// result in much slower code).
 
49
// IMPORTANT NOTE: AES_BLOCK_SIZE is in BYTES (16, 24, 32 or undefined). If
 
50
// left undefined a slower version providing variable block length is compiled
 
51
 
 
52
#define AES_BLOCK_SIZE  16
 
53
 
 
54
// The number of key schedule words for different block and key lengths
 
55
// allowing for method of computation which requires the length to be a
 
56
// multiple of the key length
 
57
//
 
58
// Nk =       4   6   8
 
59
//        -------------
 
60
// Nb = 4 |  60  60  64
 
61
//      6 |  96  90  96
 
62
//      8 | 120 120 120
 
63
 
 
64
#if !defined(AES_BLOCK_SIZE) || (AES_BLOCK_SIZE == 32)
 
65
#define AES_KS_LENGTH   120
 
66
#define AES_RC_LENGTH    29
 
67
#else
 
68
#define AES_KS_LENGTH   4 * AES_BLOCK_SIZE
 
69
#define AES_RC_LENGTH   (9 * AES_BLOCK_SIZE) / 8 - 8
 
70
#endif
 
71
 
 
72
typedef struct
 
73
{
 
74
    u_int32_t    aes_Nkey;      // the number of words in the key input block
 
75
    u_int32_t    aes_Nrnd;      // the number of cipher rounds
 
76
    u_int32_t    aes_e_key[AES_KS_LENGTH];   // the encryption key schedule
 
77
    u_int32_t    aes_d_key[AES_KS_LENGTH];   // the decryption key schedule
 
78
#if !defined(AES_BLOCK_SIZE)
 
79
    u_int32_t    aes_Ncol;      // the number of columns in the cipher state
 
80
#endif
 
81
} aes_context;
 
82
 
 
83
// THE CIPHER INTERFACE
 
84
 
 
85
#if !defined(AES_BLOCK_SIZE)
 
86
extern void aes_set_blk(aes_context *, const int);
 
87
#endif
 
88
extern void aes_set_key(aes_context *, const unsigned char [], const int, const int);
 
89
extern void aes_encrypt(const aes_context *, const unsigned char [], unsigned char []);
 
90
extern void aes_decrypt(const aes_context *, const unsigned char [], unsigned char []);
 
91
 
 
92
// The block length inputs to aes_set_block and aes_set_key are in numbers
 
93
// of bytes or bits.  The calls to subroutines must be made in the above
 
94
// order but multiple calls can be made without repeating earlier calls
 
95
// if their parameters have not changed.
 
96
 
 
97
#endif  // _AES_H