Harald Welte | 867ca29 | 2019-07-12 18:21:39 +0800 | [diff] [blame] | 1 | #ifndef __SNOW_3G__ |
| 2 | #define __SNOW_3G__ |
| 3 | |
Harald Welte | 4a2bfcb | 2019-07-12 18:27:08 +0800 | [diff] [blame] | 4 | #include <stdint.h> |
Harald Welte | 867ca29 | 2019-07-12 18:21:39 +0800 | [diff] [blame] | 5 | |
| 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif /* __cplusplus */ |
| 9 | |
| 10 | typedef uint8_t u8; |
| 11 | typedef uint32_t u32; |
| 12 | typedef uint64_t u64; |
| 13 | |
| 14 | /* Initialization. |
| 15 | * Input k[4]: Four 32-bit words making up 128-bit key. |
| 16 | * Input IV[4]: Four 32-bit words making 128-bit initialization variable. |
| 17 | * Output: All the LFSRs and FSM are initialized for key generation. |
| 18 | * See Section 4.1. |
| 19 | */ |
| 20 | |
| 21 | void snow_3g_initialize(u32 k[4], u32 IV[4]); |
| 22 | |
| 23 | /* Generation of Keystream. |
| 24 | * input n: number of 32-bit words of keystream. |
| 25 | * input z: space for the generated keystream, assumes |
| 26 | * memory is allocated already. |
| 27 | * output: generated keystream which is filled in z |
| 28 | * See section 4.2. |
| 29 | */ |
| 30 | |
| 31 | void snow_3g_generate_key_stream(u32 n, u32 *z); |
| 32 | |
| 33 | /* f8. |
| 34 | * Input key: 128 bit Confidentiality Key. |
| 35 | * Input count:32-bit Count, Frame dependent input. |
| 36 | * Input bearer: 5-bit Bearer identity (in the LSB side). |
| 37 | * Input dir:1 bit, direction of transmission. |
| 38 | * Input data: length number of bits, input bit stream. |
| 39 | * Input length: 32 bit Length, i.e., the number of bits to be encrypted or |
| 40 | * decrypted. |
| 41 | * Output data: Output bit stream. Assumes data is suitably memory |
| 42 | * allocated. |
| 43 | * Encrypts/decrypts blocks of data between 1 and 2^32 bits in length as |
| 44 | * defined in Section 3. |
| 45 | */ |
| 46 | |
| 47 | void snow_3g_f8( u8 *key, u32 count, u32 bearer, u32 dir, |
| 48 | u8 *data, u32 length ); |
| 49 | |
| 50 | /* f9. |
| 51 | * Input key: 128 bit Integrity Key. |
| 52 | * Input count:32-bit Count, Frame dependent input. |
| 53 | * Input fresh: 32-bit Random number. |
| 54 | * Input dir:1 bit, direction of transmission (in the LSB). |
| 55 | * Input data: length number of bits, input bit stream. |
| 56 | * Input length: 64 bit Length, i.e., the number of bits to be MAC'd. |
| 57 | * Output : 32 bit block used as MAC |
| 58 | * Generates 32-bit MAC using UIA2 algorithm as defined in Section 4. |
| 59 | */ |
| 60 | |
| 61 | void snow_3g_f9( u8* key, u32 count, u32 fresh, u32 dir, |
| 62 | u8 *data, u64 length, u8 *out); |
| 63 | |
| 64 | #ifdef __cplusplus |
| 65 | } |
| 66 | #endif /* __cplusplus */ |
| 67 | |
| 68 | #endif /* __SNOW_3G__ */ |