~ubuntu-branches/ubuntu/dapper/gnutls12/dapper-security

« back to all changes in this revision

Viewing changes to nettle/aes-internal.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2005-11-15 19:26:02 UTC
  • Revision ID: james.westby@ubuntu.com-20051115192602-milf548iripaq3jh
Tags: 1.2.9-2
* Install /usr/lib/pkgconfig/*.pc files.
* Depend on texinfo (>= 4.8, for the @euro{} sign).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* aes-internal.h
 
2
 *
 
3
 * The aes/rijndael block cipher.
 
4
 */
 
5
 
 
6
/* nettle, low-level cryptographics library
 
7
 *
 
8
 * Copyright (C) 2001 Niels M�ller
 
9
 *  
 
10
 * The nettle library is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU Lesser General Public License as published by
 
12
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 
13
 * option) any later version.
 
14
 * 
 
15
 * The nettle library is distributed in the hope that it will be useful, but
 
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
17
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
18
 * License for more details.
 
19
 * 
 
20
 * You should have received a copy of the GNU Lesser General Public License
 
21
 * along with the nettle library; see the file COPYING.LIB.  If not, write to
 
22
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
23
 * MA 02111-1307, USA.
 
24
 */
 
25
 
 
26
#ifndef NETTLE_AES_INTERNAL_H_INCLUDED
 
27
#define NETTLE_AES_INTERNAL_H_INCLUDED
 
28
 
 
29
#include "aes.h"
 
30
 
 
31
/* Define to use only small tables. */
 
32
#ifndef AES_SMALL
 
33
# define AES_SMALL 0
 
34
#endif
 
35
 
 
36
#if AES_SMALL
 
37
# define AES_TABLE_SIZE 1
 
38
#else
 
39
# define AES_TABLE_SIZE 4
 
40
#endif
 
41
 
 
42
/* Name mangling */
 
43
#define _aes_crypt _nettle_aes_crypt
 
44
 
 
45
/* Assembler code using the table should get link errors if linked
 
46
 * against a small table. */
 
47
#if AES_SMALL
 
48
# define _aes_encrypt_table _nettle_aes_encrypt_table_small
 
49
# define _aes_decrypt_table _nettle_aes_decrypt_table_small
 
50
#else
 
51
# define _aes_encrypt_table _nettle_aes_encrypt_table
 
52
# define _aes_decrypt_table _nettle_aes_decrypt_table
 
53
#endif
 
54
 
 
55
struct aes_table
 
56
{
 
57
  uint8_t sbox[0x100];
 
58
  unsigned idx[3][4];
 
59
 
 
60
  /* Variant of the idx array suitable for the sparc
 
61
   * assembler code.
 
62
   *
 
63
   * sparc_idx[0][i] = idx[0][i] * 4 + 2
 
64
   * sparc_idx[1][i] = idx[2][i] * 4
 
65
   */
 
66
  
 
67
  unsigned sparc_idx [2][4]; 
 
68
 
 
69
  uint32_t table[AES_TABLE_SIZE][0x100];
 
70
};
 
71
 
 
72
void
 
73
_aes_crypt(const struct aes_ctx *ctx,
 
74
           const struct aes_table *T,
 
75
           unsigned length, uint8_t *dst,
 
76
           const uint8_t *src);
 
77
 
 
78
/* Macros */
 
79
#define ROTBYTE(x) (((x) >> 8) | (((x) & 0xff) << 24))
 
80
#define ROTRBYTE(x) (((x) << 8) | (((x) >> 24) & 0xff))
 
81
#define SUBBYTE(x, box) (((box)[((x) & 0xff)]) | \
 
82
                        ((box)[(((x) >> 8) & 0xff)] << 8) | \
 
83
                        ((box)[(((x) >> 16) & 0xff)] << 16) | \
 
84
                        ((box)[(((x) >> 24) & 0xff)] << 24))
 
85
 
 
86
/* Internal tables */
 
87
extern const struct aes_table _aes_encrypt_table;
 
88
extern const struct aes_table _aes_decrypt_table;
 
89
 
 
90
#define aes_sbox (_aes_encrypt_table.sbox)
 
91
 
 
92
#endif /* NETTLE_AES_INTERNAL_H_INCLUDED */