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