]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/skein/threefishApi.c
staging: crypto: skein: rename macros
[karo-tx-linux.git] / drivers / staging / skein / threefishApi.c
1
2
3 #include <linux/string.h>
4 #include <threefishApi.h>
5
6 void threefish_set_key(struct threefish_key *key_ctx,
7                        enum threefish_size state_size,
8                        u64 *key_data, u64 *tweak)
9 {
10         int key_words = state_size / 64;
11         int i;
12         u64 parity = KEY_SCHEDULE_CONST;
13
14         key_ctx->tweak[0] = tweak[0];
15         key_ctx->tweak[1] = tweak[1];
16         key_ctx->tweak[2] = tweak[0] ^ tweak[1];
17
18         for (i = 0; i < key_words; i++) {
19                 key_ctx->key[i] = key_data[i];
20                 parity ^= key_data[i];
21         }
22         key_ctx->key[i] = parity;
23         key_ctx->state_size = state_size;
24 }
25
26 void threefish_encrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
27                                    u8 *out)
28 {
29         u64 plain[SKEIN_MAX_STATE_WORDS];        /* max number of words*/
30         u64 cipher[SKEIN_MAX_STATE_WORDS];
31
32         skein_get64_lsb_first(plain, in, key_ctx->state_size / 64);
33         threefish_encrypt_block_words(key_ctx, plain, cipher);
34         skein_put64_lsb_first(out, cipher, key_ctx->state_size / 8);
35 }
36
37 void threefish_encrypt_block_words(struct threefish_key *key_ctx, u64 *in,
38                                    u64 *out)
39 {
40         switch (key_ctx->state_size) {
41         case THREEFISH_256:
42                 threefish_encrypt_256(key_ctx, in, out);
43                 break;
44         case THREEFISH_512:
45                 threefish_encrypt_512(key_ctx, in, out);
46                 break;
47         case THREEFISH_1024:
48                 threefish_encrypt_1024(key_ctx, in, out);
49                 break;
50         }
51 }
52
53 void threefish_decrypt_block_bytes(struct threefish_key *key_ctx, u8 *in,
54                                    u8 *out)
55 {
56         u64 plain[SKEIN_MAX_STATE_WORDS];        /* max number of words*/
57         u64 cipher[SKEIN_MAX_STATE_WORDS];
58
59         skein_get64_lsb_first(cipher, in, key_ctx->state_size / 64);
60         threefish_decrypt_block_words(key_ctx, cipher, plain);
61         skein_put64_lsb_first(out, plain, key_ctx->state_size / 8);
62 }
63
64 void threefish_decrypt_block_words(struct threefish_key *key_ctx, u64 *in,
65                                    u64 *out)
66 {
67         switch (key_ctx->state_size) {
68         case THREEFISH_256:
69                 threefish_decrypt_256(key_ctx, in, out);
70                 break;
71         case THREEFISH_512:
72                 threefish_decrypt_512(key_ctx, in, out);
73                 break;
74         case THREEFISH_1024:
75                 threefish_decrypt_1024(key_ctx, in, out);
76                 break;
77         }
78 }
79