ssl_tls: fix format warning in ssl_parse_certificate() on x86_64
[tropicssl.git] / include / tropicssl / des.h
blobfce141cff984de3298a4fe50c29ba6f366d32ed8
1 /**
2 * \file des.h
4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
6 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * * Neither the names of PolarSSL or XySSL nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef TROPICSSL_DES_H
36 #define TROPICSSL_DES_H
38 #define DES_ENCRYPT 1
39 #define DES_DECRYPT 0
41 /**
42 * \brief DES context structure
44 typedef struct {
45 int mode; /*!< encrypt/decrypt */
46 unsigned long sk[32]; /*!< DES subkeys */
47 } des_context;
49 /**
50 * \brief Triple-DES context structure
52 typedef struct {
53 int mode; /*!< encrypt/decrypt */
54 unsigned long sk[96]; /*!< 3DES subkeys */
55 } des3_context;
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
61 /**
62 * \brief DES key schedule (56-bit, encryption)
64 * \param ctx DES context to be initialized
65 * \param key 8-byte secret key
67 void des_setkey_enc(des_context * ctx, const unsigned char key[8]);
69 /**
70 * \brief DES key schedule (56-bit, decryption)
72 * \param ctx DES context to be initialized
73 * \param key 8-byte secret key
75 void des_setkey_dec(des_context * ctx, const unsigned char key[8]);
77 /**
78 * \brief Triple-DES key schedule (112-bit, encryption)
80 * \param ctx 3DES context to be initialized
81 * \param key 16-byte secret key
83 void des3_set2key_enc(des3_context * ctx, const unsigned char key[16]);
85 /**
86 * \brief Triple-DES key schedule (112-bit, decryption)
88 * \param ctx 3DES context to be initialized
89 * \param key 16-byte secret key
91 void des3_set2key_dec(des3_context * ctx, const unsigned char key[16]);
93 /**
94 * \brief Triple-DES key schedule (168-bit, encryption)
96 * \param ctx 3DES context to be initialized
97 * \param key 24-byte secret key
99 void des3_set3key_enc(des3_context * ctx, const unsigned char key[24]);
102 * \brief Triple-DES key schedule (168-bit, decryption)
104 * \param ctx 3DES context to be initialized
105 * \param key 24-byte secret key
107 void des3_set3key_dec(des3_context * ctx, const unsigned char key[24]);
110 * \brief DES-ECB block encryption/decryption
112 * \param ctx DES context
113 * \param input 64-bit input block
114 * \param output 64-bit output block
116 void des_crypt_ecb(des_context * ctx,
117 const unsigned char input[8],
118 unsigned char output[8]);
121 * \brief DES-CBC buffer encryption/decryption
123 * \param ctx DES context
124 * \param mode DES_ENCRYPT or DES_DECRYPT
125 * \param length length of the input data
126 * \param iv initialization vector (updated after use)
127 * \param input buffer holding the input data
128 * \param output buffer holding the output data
130 void des_crypt_cbc(des_context * ctx,
131 int mode,
132 int length,
133 unsigned char iv[8],
134 const unsigned char *input,
135 unsigned char *output);
138 * \brief 3DES-ECB block encryption/decryption
140 * \param ctx 3DES context
141 * \param input 64-bit input block
142 * \param output 64-bit output block
144 void des3_crypt_ecb(des3_context * ctx,
145 const unsigned char input[8],
146 unsigned char output[8]);
149 * \brief 3DES-CBC buffer encryption/decryption
151 * \param ctx 3DES context
152 * \param mode DES_ENCRYPT or DES_DECRYPT
153 * \param length length of the input data
154 * \param iv initialization vector (updated after use)
155 * \param input buffer holding the input data
156 * \param output buffer holding the output data
158 void des3_crypt_cbc(des3_context * ctx,
159 int mode,
160 int length,
161 unsigned char iv[8],
162 const unsigned char *input,
163 unsigned char *output);
166 * \brief Checkup routine
168 * \return 0 if successful, or 1 if the test failed
170 int des_self_test(int verbose);
172 #ifdef __cplusplus
174 #endif
175 #endif /* des.h */