xts.h
Go to the documentation of this file.
1 /**
2  * @file xts.h
3  * @brief XEX-based tweaked-codebook mode with ciphertext stealing (XTS)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCrypto Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
29  **/
30 
31 #ifndef _XTS_H
32 #define _XTS_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //RC2 support?
38 #if (RC2_SUPPORT == ENABLED)
39  #include "cipher/rc2.h"
40 #endif
41 
42 //RC6 support?
43 #if (RC6_SUPPORT == ENABLED)
44  #include "cipher/rc6.h"
45 #endif
46 
47 //IDEA support?
48 #if (IDEA_SUPPORT == ENABLED)
49  #include "cipher/idea.h"
50 #endif
51 
52 //DES support?
53 #if (DES_SUPPORT == ENABLED)
54  #include "cipher/des.h"
55 #endif
56 
57 //Triple DES support?
58 #if (DES3_SUPPORT == ENABLED)
59  #include "cipher/des3.h"
60 #endif
61 
62 //AES support?
63 #if (AES_SUPPORT == ENABLED)
64  #include "cipher/aes.h"
65 #endif
66 
67 //Blowfish support?
68 #if (BLOWFISH_SUPPORT == ENABLED)
69  #include "cipher/blowfish.h"
70 #endif
71 
72 //Camellia support?
73 #if (CAMELLIA_SUPPORT == ENABLED)
74  #include "cipher/camellia.h"
75 #endif
76 
77 //SEED support?
78 #if (SEED_SUPPORT == ENABLED)
79  #include "cipher/seed.h"
80 #endif
81 
82 //ARIA support?
83 #if (ARIA_SUPPORT == ENABLED)
84  #include "cipher/aria.h"
85 #endif
86 
87 //PRESENT support?
88 #if (PRESENT_SUPPORT == ENABLED)
89  #include "cipher/present.h"
90 #endif
91 
92 //C++ guard
93 #ifdef __cplusplus
94 extern "C" {
95 #endif
96 
97 
98 /**
99  * @brief XTS context
100  **/
101 
102 typedef struct
103 {
105  uint8_t cipherContext1[MAX_CIPHER_CONTEXT_SIZE];
106  uint8_t cipherContext2[MAX_CIPHER_CONTEXT_SIZE];
107 } XtsContext;
108 
109 
110 //XTS related functions
111 error_t xtsInit(XtsContext *context, const CipherAlgo *cipherAlgo,
112  const void *key, size_t keyLen);
113 
114 error_t xtsEncrypt(XtsContext *context, const uint8_t *i, const uint8_t *p,
115  uint8_t *c, size_t length);
116 
117 error_t xtsDecrypt(XtsContext *context, const uint8_t *i, const uint8_t *c,
118  uint8_t *p, size_t length);
119 
120 void xtsMul(uint8_t *x, const uint8_t *a);
121 void xtsXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b);
122 
123 //C++ guard
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 #endif
uint8_t length
Definition: dtls_misc.h:149
PRESENT encryption algorithm.
XTS context.
Definition: xts.h:102
uint8_t a
Definition: ndp.h:410
RC6-32/20 block cipher.
uint8_t b[6]
Definition: dtls_misc.h:139
uint8_t p
Definition: ndp.h:298
ARIA encryption algorithm.
error_t
Error codes.
Definition: error.h:42
void xtsXorBlock(uint8_t *x, const uint8_t *a, const uint8_t *b)
XOR operation.
Definition: xts.c:282
void xtsMul(uint8_t *x, const uint8_t *a)
Multiplication by x in GF(2^128)
Definition: xts.c:252
AES (Advanced Encryption Standard)
General definitions for cryptographic algorithms.
IDEA encryption algorithm.
Blowfish encryption algorithm.
SEED encryption algorithm.
DES (Data Encryption Standard)
error_t xtsDecrypt(XtsContext *context, const uint8_t *i, const uint8_t *c, uint8_t *p, size_t length)
Decrypt a data unit using XTS.
Definition: xts.c:171
error_t xtsInit(XtsContext *context, const CipherAlgo *cipherAlgo, const void *key, size_t keyLen)
Initialize XTS context.
Definition: xts.c:57
Common interface for encryption algorithms.
Definition: crypto.h:1150
const CipherAlgo * cipherAlgo
Definition: xts.h:104
#define MAX_CIPHER_CONTEXT_SIZE
Definition: crypto.h:866
error_t xtsEncrypt(XtsContext *context, const uint8_t *i, const uint8_t *p, uint8_t *c, size_t length)
Encrypt a data unit using XTS.
Definition: xts.c:106
Triple DES (Triple Data Encryption Algorithm)
RC2 block cipher.
Camellia encryption algorithm.