47#if !defined(MBEDTLS_CONFIG_FILE)
50#include MBEDTLS_CONFIG_FILE
53#if defined(MBEDTLS_XTEA_C)
60#if defined(MBEDTLS_SELF_TEST)
61#if defined(MBEDTLS_PLATFORM_C)
65#define mbedtls_printf printf
69#if !defined(MBEDTLS_XTEA_ALT)
75#define GET_UINT32_BE(n,b,i) \
77 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
78 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
79 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
80 | ( (uint32_t) (b)[(i) + 3] ); \
85#define PUT_UINT32_BE(n,b,i) \
87 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
88 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
89 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
90 (b)[(i) + 3] = (unsigned char) ( (n) ); \
116 for(
i = 0;
i < 4;
i++ )
118 GET_UINT32_BE(
ctx->k[
i],
key,
i << 2 );
126 const unsigned char input[8],
unsigned char output[8])
139 for(
i = 0;
i < 32;
i++ )
150 for(
i = 0;
i < 32;
i++ )
158 PUT_UINT32_BE(
v0, output, 0 );
159 PUT_UINT32_BE(
v1, output, 4 );
164#if defined(MBEDTLS_CIPHER_MODE_CBC)
169 unsigned char iv[8],
const unsigned char *
input,
170 unsigned char *output)
173 unsigned char temp[8];
185 for(
i = 0;
i < 8;
i++ )
186 output[
i] = (
unsigned char)( output[
i] ^ iv[
i] );
199 for(
i = 0;
i < 8;
i++ )
200 output[
i] = (
unsigned char)(
input[
i] ^ iv[
i] );
216#if defined(MBEDTLS_SELF_TEST)
222static const unsigned char xtea_test_key[6][16] =
224 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
225 0x0c, 0x0d, 0x0e, 0x0f },
226 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
227 0x0c, 0x0d, 0x0e, 0x0f },
228 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
229 0x0c, 0x0d, 0x0e, 0x0f },
230 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00 },
232 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0x00, 0x00, 0x00, 0x00 },
234 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235 0x00, 0x00, 0x00, 0x00 }
238static const unsigned char xtea_test_pt[6][8] =
240 { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
241 { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
242 { 0x5a, 0x5b, 0x6e, 0x27, 0x89, 0x48, 0xd7, 0x7f },
243 { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48 },
244 { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
245 { 0x70, 0xe1, 0x22, 0x5d, 0x6e, 0x4e, 0x76, 0x55 }
248static const unsigned char xtea_test_ct[6][8] =
250 { 0x49, 0x7d, 0xf3, 0xd0, 0x72, 0x61, 0x2c, 0xb5 },
251 { 0xe7, 0x8f, 0x2d, 0x13, 0x74, 0x43, 0x41, 0xd8 },
252 { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 },
253 { 0xa0, 0x39, 0x05, 0x89, 0xf8, 0xb8, 0xef, 0xa5 },
254 { 0xed, 0x23, 0x37, 0x5a, 0x82, 0x1a, 0x8c, 0x2d },
255 { 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }
261int mbedtls_xtea_self_test(
int verbose )
264 unsigned char buf[8];
268 for(
i = 0;
i < 6;
i++ )
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLsizei GLsizei * length
GLenum GLenum GLenum input
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define memcpy(s1, s2, n)
static int sum(int x_, int y_)
Configuration options (set of defines)
XTEA block cipher (32-bit)
void mbedtls_xtea_setup(mbedtls_xtea_context *ctx, const unsigned char key[16])
XTEA key schedule.
#define MBEDTLS_XTEA_ENCRYPT
void mbedtls_xtea_free(mbedtls_xtea_context *ctx)
Clear XTEA context.
int mbedtls_xtea_crypt_ecb(mbedtls_xtea_context *ctx, int mode, const unsigned char input[8], unsigned char output[8])
XTEA cipher function.
int mbedtls_xtea_crypt_cbc(mbedtls_xtea_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
XTEA CBC cipher function.
#define MBEDTLS_ERR_XTEA_INVALID_INPUT_LENGTH
void mbedtls_xtea_init(mbedtls_xtea_context *ctx)
Initialize XTEA context.
#define MBEDTLS_XTEA_DECRYPT