The friendly Operating System for the Internet of Things
3des.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Freie Universit├Ąt Berlin, Computer Systems & Telematics
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <stdint.h>
26 
27 #include "crypto/ciphers.h"
28 
29 #ifndef THREEDES_H
30 #define THREEDES_H
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define THREEDES_BLOCK_SIZE 8
37 #define THREEDES_MAX_KEY_SIZE 24
38 
39 #define ROLc(x, y) \
40  ((((unsigned long) (x) << (unsigned long) ((y) & 31)) | \
41  (((unsigned long) (x) & 0xFFFFFFFFUL) >> \
42  (unsigned long) (32 - ((y) & 31)))) & 0xFFFFFFFFUL)
43 
44 #define RORc(x, y) \
45  (((((unsigned long) (x) & 0xFFFFFFFFUL) >> \
46  (unsigned long) ((y) & 31)) | \
47  ((unsigned long) (x) << (unsigned long) (32 - ((y) & 31)))) & \
48  0xFFFFFFFFUL)
49 
50 //source: http://hostap.epitest.fi/wpa_supplicant/devel/common_8h.html
51 #define WPA_GET_BE32(a) \
52  ((((uint32_t) (a)[0]) << 24) | \
53  (((uint32_t) (a)[1]) << 16) | \
54  (((uint32_t) (a)[2]) << 8 ) | ((uint32_t) (a)[3]))
55 
56 //source: http://hostap.epitest.fi/wpa_supplicant/devel/common_8h.html
57 #define WPA_PUT_BE32(a, val) \
58  do { \
59  (a)[0] = (uint8_t) ((((uint32_t) (val)) >> 24) & 0xff); \
60  (a)[1] = (uint8_t) ((((uint32_t) (val)) >> 16) & 0xff); \
61  (a)[2] = (uint8_t) ((((uint32_t) (val)) >> 8) & 0xff); \
62  (a)[3] = (uint8_t) (((uint32_t) (val)) & 0xff); \
63  } while (0)
64 
65 
66 
67 
68 static const uint32_t bytebit[8] = {0200, 0100, 040, 020, 010, 04, 02, 01};
69 
70 static const uint32_t bigbyte[24] = {
71  0x800000UL, 0x400000UL, 0x200000UL, 0x100000UL,
72  0x80000UL, 0x40000UL, 0x20000UL, 0x10000UL,
73  0x8000UL, 0x4000UL, 0x2000UL, 0x1000UL,
74  0x800UL, 0x400UL, 0x200UL, 0x100UL,
75  0x80UL, 0x40UL, 0x20UL, 0x10UL,
76  0x8UL, 0x4UL, 0x2UL, 0x1L
77 };
92 int tripledes_init(cipher_context_t *context, const uint8_t* key, uint8_t keySize);
93 
111 int tripledes_encrypt(const cipher_context_t *context, const uint8_t *plain, uint8_t *crypt);
112 
130 int tripledes_decrypt(const cipher_context_t *context, const uint8_t *crypt, uint8_t *plain);
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
137 #endif /* THREEDES_H */
int tripledes_decrypt(const cipher_context_t *context, const uint8_t *crypt, uint8_t *plain)
decrypts one cipher-block and saves the plain-block in plain.
int tripledes_encrypt(const cipher_context_t *context, const uint8_t *plain, uint8_t *crypt)
encrypts one plain-block and saves the result in crypt.
the context for cipher-operations
Definition: ciphers.h:74
int tripledes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize)
initializes the 3DES Cipher-algorithm with the passed parameters
stdio.h wrapper for MSP430
Headers for the packet encryption class.
stdlib.h wrapper for MSP430