~ubuntu-branches/ubuntu/saucy/nettle/saucy-proposed

« back to all changes in this revision

Viewing changes to des-compat.h

  • Committer: Bazaar Package Importer
  • Author(s): Marek Habersack
  • Date: 2004-05-04 15:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20040504155602-7jbhw5mabvwksl3j
Tags: upstream-1.10
Import upstream version 1.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* des-compat.h
 
2
 *
 
3
 * The des block cipher, libdes/openssl-style interface.
 
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_DES_COMPAT_H_INCLUDED
 
27
#define NETTLE_DES_COMPAT_H_INCLUDED
 
28
 
 
29
/* According to Assar, des_set_key, des_set_key_odd_parity,
 
30
 * des_is_weak_key, plus the encryption functions (des_*_encrypt and
 
31
 * des_cbc_cksum) would be a pretty useful subset. */
 
32
 
 
33
/* NOTE: This is quite experimental, and not all functions are
 
34
 * implemented. Contributions, in particular test cases are welcome. */
 
35
 
 
36
#include "des.h"
 
37
 
 
38
/* We use some name mangling, to avoid collisions with either other
 
39
 * nettle functions or with libcrypto. */
 
40
 
 
41
#define des_ecb3_encrypt nettle_openssl_des_ecb3_encrypt
 
42
#define des_cbc_cksum nettle_openssl_des_cbc_cksum
 
43
#define des_ncbc_encrypt nettle_openssl_des_ncbc_encrypt
 
44
#define des_cbc_encrypt nettle_openssl_des_cbc_encrypt
 
45
#define des_ecb_encrypt nettle_openssl_des_ecb_encrypt
 
46
#define des_ede3_cbc_encrypt nettle_openssl_des_ede3_cbc_encrypt
 
47
#define des_set_odd_parity nettle_openssl_des_set_odd_parity
 
48
#define des_check_key nettle_openssl_des_check_key
 
49
#define des_key_sched nettle_openssl_des_key_sched
 
50
#define des_is_weak_key nettle_openssl_des_is_weak_key
 
51
 
 
52
/* An extra alias */
 
53
#undef des_set_key
 
54
#define des_set_key nettle_openssl_des_key_sched
 
55
 
 
56
enum { DES_DECRYPT = 0, DES_ENCRYPT = 1 };
 
57
 
 
58
/* Types */
 
59
/* NOTE: Typedef:ed arrays should be avoided, but they're used here
 
60
 * for compatibility. */
 
61
 
 
62
typedef uint32_t DES_LONG;
 
63
 
 
64
typedef struct des_ctx des_key_schedule[1];
 
65
 
 
66
typedef uint8_t des_cblock[DES_BLOCK_SIZE];
 
67
 
 
68
/* Aliases */
 
69
#define des_ecb2_encrypt(i,o,k1,k2,e) \
 
70
        des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
 
71
 
 
72
#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
 
73
        des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
 
74
 
 
75
/* Global flag */
 
76
extern int des_check_key;
 
77
 
 
78
/* Prototypes */
 
79
 
 
80
/* Typing is a little confusing. Since both des_cblock and
 
81
   des_key_schedule are typedef:ed arrays, it automatically decay to
 
82
   a pointers.
 
83
 
 
84
   But the functions are declared taking pointers to des_cblock, i.e.
 
85
   pointers to arrays. And on the other hand, they take plain
 
86
   des_key_schedule arguments, which is equivalent to pointers to
 
87
   struct des_ctx.  */
 
88
void
 
89
des_ecb3_encrypt(const des_cblock *src, des_cblock *dst,
 
90
                 des_key_schedule k1,
 
91
                 des_key_schedule k2,
 
92
                 des_key_schedule k3, int enc);
 
93
 
 
94
/* des_cbc_cksum in libdes returns a 32 bit integer, representing the
 
95
 * latter half of the output block, using little endian byte order. */
 
96
uint32_t
 
97
des_cbc_cksum(const des_cblock *src, des_cblock *dst,
 
98
              long length, des_key_schedule ctx,
 
99
              const des_cblock *iv);
 
100
 
 
101
/* NOTE: Doesn't update iv. */
 
102
void
 
103
des_cbc_encrypt(const des_cblock *src, des_cblock *dst, long length,
 
104
                des_key_schedule ctx, const des_cblock *iv,
 
105
                int enc);
 
106
 
 
107
/* Similar, but updates iv. */
 
108
void
 
109
des_ncbc_encrypt(const des_cblock *src, des_cblock *dst, long length,
 
110
                 des_key_schedule ctx, des_cblock *iv,
 
111
                 int enc);
 
112
 
 
113
void
 
114
des_ecb_encrypt(const des_cblock *src, des_cblock *dst,
 
115
                des_key_schedule ctx, int enc);
 
116
 
 
117
void
 
118
des_ede3_cbc_encrypt(const des_cblock *src, des_cblock *dst, long length,
 
119
                     des_key_schedule k1,
 
120
                     des_key_schedule k2,
 
121
                     des_key_schedule k3,
 
122
                     des_cblock *iv,
 
123
                     int enc);
 
124
 
 
125
int
 
126
des_set_odd_parity(des_cblock *key);
 
127
 
 
128
int
 
129
des_key_sched(const des_cblock *key, des_key_schedule ctx);
 
130
 
 
131
int
 
132
des_is_weak_key(const des_cblock *key);
 
133
 
 
134
#endif /* NETTLE_DES_COMPAT_H_INCLUDED */