camellia.h 2.84 KB
Newer Older
1
/* camellia.h
Niels Möller's avatar
Niels Möller committed
2 3 4 5
 *
 * Copyright (C) 2006,2007
 * NTT (Nippon Telegraph and Telephone Corporation).
 *
6 7
 * Copyright (C) 2010 Niels Mller
 *
Niels Möller's avatar
Niels Möller committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

23 24
#ifndef NETTLE_CAMELLIA_H_INCLUDED
#define NETTLE_CAMELLIA_H_INCLUDED
Niels Möller's avatar
Niels Möller committed
25

26 27 28
#include "nettle-types.h"

#ifdef __cplusplus
Niels Möller's avatar
Niels Möller committed
29 30 31
extern "C" {
#endif

32 33 34 35 36
/* Name mangling */
#define camellia_set_key nettle_camellia_set_key
#define camellia_encrypt nettle_camellia_encrypt
#define camellia_decrypt nettle_camellia_decrypt

Niels Möller's avatar
Niels Möller committed
37
#define CAMELLIA_BLOCK_SIZE 16
38 39 40 41
/* Valid key sizes are 128, 192 or 256 bits (16, 24 or 32 bytes) */
#define CAMELLIA_MIN_KEY_SIZE 16
#define CAMELLIA_MAX_KEY_SIZE 32
#define CAMELLIA_KEY_SIZE 32
Niels Möller's avatar
Niels Möller committed
42

43 44 45
struct camellia_ctx
{
  int camellia128;
Niels Möller's avatar
Niels Möller committed
46

47 48 49 50 51 52 53 54 55
  /* For 128-bit keys, there are 18 regular rounds, pre- and
     post-whitening, and two FL and FLINV rounds, using a total of 26
     subkeys, each of 64 bit. For 192- and 256-bit keys, there are 6
     additional regular rounds and one additional FL and FLINV, using
     a total of 34 subkeys. */
  /* The clever combination of subkeys imply one of the pre- and
     post-whitening keys is folded fith the round keys, so that subkey
     subkey #1 and the last one (#25 or #33) is not used. FIXME:
     Renumber to eliminate them. */
56
  uint64_t keys[34];
57
};
Niels Möller's avatar
Niels Möller committed
58

59 60 61
void
camellia_set_key(struct camellia_ctx *ctx,
		 unsigned length, const uint8_t *key);
Niels Möller's avatar
Niels Möller committed
62

63 64 65 66 67 68 69 70
void
camellia_encrypt(const struct camellia_ctx *ctx,
		 unsigned length, uint8_t *dst,
		 const uint8_t *src);
void
camellia_decrypt(const struct camellia_ctx *ctx,
		 unsigned length, uint8_t *dst,
		 const uint8_t *src);
Niels Möller's avatar
Niels Möller committed
71

72 73 74
#if 0
/* FIXME: Use a single crypt function, and let key setup for
   decryption reverse the order of the subkeys. */
Niels Möller's avatar
Niels Möller committed
75

76 77 78
void
camellia_set_encrypt_key(struct camellia_ctx *ctx,
			 unsigned length, const uint8_t *key);
Niels Möller's avatar
Niels Möller committed
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93
void
camellia_set_decrypt_key(struct camellia_ctx *ctx,
			 unsigned length, const uint8_t *key);

void
camellia_crypt(struct camellia_ctx *ctx,
	       unsigned length, uint8_t *dst,
	       const uint8_t *src);

void
camellia_invert_key(struct camellia_ctx *dst,
		    const struct camellia_ctx *src);

#endif
Niels Möller's avatar
Niels Möller committed
94 95 96 97
#ifdef  __cplusplus
}
#endif

98
#endif /* NETTLE_CAMELLIA_H_INCLUDED */