author | Will Fiveash <will.fiveash@oracle.com> |
Fri, 24 Mar 2017 12:29:03 -0500 | |
changeset 7950 | 50d75ee82dad |
permissions | -rw-r--r-- |
7950
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
1 |
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
2 |
/* lib/crypto/ucrypto/enc_provider/aes.c */ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
3 |
/* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
4 |
* Copyright (C) 2003, 2007, 2008, 2009 by the Massachusetts Institute of Technology. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
5 |
* All rights reserved. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
6 |
* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
7 |
* Export of this software from the United States of America may |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
8 |
* require a specific license from the United States Government. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
9 |
* It is the responsibility of any person or organization contemplating |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
10 |
* export to obtain such a license before exporting. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
11 |
* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
12 |
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
13 |
* distribute this software and its documentation for any purpose and |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
14 |
* without fee is hereby granted, provided that the above copyright |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
15 |
* notice appear in all copies and that both that copyright notice and |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
16 |
* this permission notice appear in supporting documentation, and that |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
17 |
* the name of M.I.T. not be used in advertising or publicity pertaining |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
18 |
* to distribution of the software without specific, written prior |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
19 |
* permission. Furthermore if you modify this software you must label |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
20 |
* your software as modified software and not distribute it in such a |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
21 |
* fashion that it might be confused with the original M.I.T. software. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
22 |
* M.I.T. makes no representations about the suitability of |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
23 |
* this software for any purpose. It is provided "as is" without express |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
24 |
* or implied warranty. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
25 |
*/ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
26 |
/* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
27 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
28 |
*/ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
29 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
30 |
#include "crypto_int.h" |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
31 |
#include <libucrypto.h> |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
32 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
33 |
#define BLOCK_SIZE 16 |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
34 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
35 |
#define ENCRYPT_OP 1 |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
36 |
#define DECRYPT_OP 2 |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
37 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
38 |
/* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
39 |
* xorblock is used in the camellia cbc mac fuction, copied from the openssl |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
40 |
* camellia.c. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
41 |
*/ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
42 |
static void |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
43 |
xorblock(unsigned char *out, const unsigned char *in) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
44 |
{ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
45 |
int z; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
46 |
for (z = 0; z < BLOCK_SIZE / 4; z++) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
47 |
unsigned char *outptr = &out[z * 4]; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
48 |
unsigned char *inptr = (unsigned char *)&in[z * 4]; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
49 |
/* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
50 |
* Use unaligned accesses. On x86, this will probably still be faster |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
51 |
* than multiple byte accesses for unaligned data, and for aligned data |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
52 |
* should be far better. (One test indicated about 2.4% faster |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
53 |
* encryption for 1024-byte messages.) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
54 |
* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
55 |
* If some other CPU has really slow unaligned-word or byte accesses, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
56 |
* perhaps this function (or the load/store helpers?) should test for |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
57 |
* alignment first. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
58 |
* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
59 |
* If byte accesses are faster than unaligned words, we may need to |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
60 |
* conditionalize on CPU type, as that may be hard to determine |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
61 |
* automatically. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
62 |
*/ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
63 |
store_32_n(load_32_n(outptr) ^ load_32_n(inptr), outptr); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
64 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
65 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
66 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
67 |
/* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
68 |
* The cbc_docrypt function is here to handle the case where there is only 1 |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
69 |
* block of plain/cipher text to process. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
70 |
*/ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
71 |
static krb5_error_code |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
72 |
cbc_docrypt(krb5_key key, const krb5_data *ivec, krb5_crypto_iov *data, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
73 |
size_t num_data, int op_type) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
74 |
{ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
75 |
int ret = 0; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
76 |
unsigned char iblock[BLOCK_SIZE], oblock[BLOCK_SIZE]; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
77 |
size_t olen = sizeof (oblock); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
78 |
unsigned char tmp_iv[BLOCK_SIZE]; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
79 |
struct iov_cursor cursor; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
80 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
81 |
if (ivec && ivec->data){ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
82 |
if (ivec->length != sizeof (tmp_iv)) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
83 |
return KRB5_CRYPTO_INTERNAL; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
84 |
memcpy(tmp_iv, ivec->data, ivec->length); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
85 |
} else { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
86 |
memset(tmp_iv, 0, sizeof (tmp_iv)); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
87 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
88 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
89 |
/* Init iovec cursor to gather data for encypting (FALSE) */ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
90 |
k5_iov_cursor_init(&cursor, data, num_data, BLOCK_SIZE, FALSE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
91 |
k5_iov_cursor_get(&cursor, iblock); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
92 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
93 |
if (op_type == ENCRYPT_OP) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
94 |
if (ucrypto_encrypt(CRYPTO_CAMELLIA_CBC, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
95 |
key->keyblock.contents, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
96 |
key->keyblock.length, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
97 |
tmp_iv, sizeof (tmp_iv), |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
98 |
iblock, sizeof (iblock), |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
99 |
oblock, &olen) != CRYPTO_SUCCESS) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
100 |
ret = KRB5_CRYPTO_INTERNAL; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
101 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
102 |
} else { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
103 |
if (ucrypto_decrypt(CRYPTO_CAMELLIA_CBC, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
104 |
key->keyblock.contents, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
105 |
key->keyblock.length, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
106 |
tmp_iv, sizeof (tmp_iv), |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
107 |
iblock, sizeof (iblock), |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
108 |
oblock, &olen) != CRYPTO_SUCCESS) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
109 |
ret = KRB5_CRYPTO_INTERNAL; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
110 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
111 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
112 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
113 |
if (!ret) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
114 |
assert(olen == BLOCK_SIZE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
115 |
k5_iov_cursor_put(&cursor, oblock); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
116 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
117 |
if (ivec && ivec->data) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
118 |
if (op_type == ENCRYPT_OP) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
119 |
memcpy(ivec->data, oblock, BLOCK_SIZE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
120 |
else |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
121 |
memcpy(ivec->data, iblock, BLOCK_SIZE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
122 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
123 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
124 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
125 |
zap(iblock, sizeof (iblock)); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
126 |
zap(oblock, sizeof (oblock)); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
127 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
128 |
return ret; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
129 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
130 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
131 |
static krb5_error_code |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
132 |
cts_docrypt(krb5_key key, const krb5_data *ivec, krb5_crypto_iov *data, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
133 |
size_t num_data, size_t dlen, size_t dblks, int op_type) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
134 |
{ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
135 |
int ret = 0; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
136 |
size_t olen = dlen; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
137 |
unsigned char *obuf, *dbuf; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
138 |
unsigned char iv_cts[BLOCK_SIZE]; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
139 |
struct iov_cursor cursor; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
140 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
141 |
if (ivec && ivec->data){ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
142 |
if (ivec->length != sizeof (iv_cts)) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
143 |
return KRB5_CRYPTO_INTERNAL; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
144 |
memcpy(iv_cts, ivec->data, ivec->length); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
145 |
} else { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
146 |
memset(iv_cts, 0, sizeof (iv_cts)); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
147 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
148 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
149 |
obuf = malloc(olen); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
150 |
if (!obuf) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
151 |
return ENOMEM; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
152 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
153 |
dbuf = malloc(dlen); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
154 |
if (!dbuf){ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
155 |
free(obuf); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
156 |
return ENOMEM; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
157 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
158 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
159 |
/* Init iov cursor to gather data for encypting/decrypting (FALSE) */ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
160 |
k5_iov_cursor_init(&cursor, data, num_data, dlen, FALSE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
161 |
/* Get all the data to be encrypted/decrypted into dbuf */ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
162 |
k5_iov_cursor_get(&cursor, dbuf); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
163 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
164 |
if (op_type == ENCRYPT_OP) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
165 |
if (ucrypto_encrypt(CRYPTO_CAMELLIA_CTS, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
166 |
key->keyblock.contents, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
167 |
key->keyblock.length, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
168 |
iv_cts, sizeof (iv_cts), |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
169 |
dbuf, dlen, obuf, &olen) != CRYPTO_SUCCESS) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
170 |
ret = KRB5_CRYPTO_INTERNAL; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
171 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
172 |
} else { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
173 |
if (ucrypto_decrypt(CRYPTO_CAMELLIA_CTS, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
174 |
key->keyblock.contents, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
175 |
key->keyblock.length, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
176 |
iv_cts, sizeof (iv_cts), |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
177 |
dbuf, dlen, obuf, &olen) != CRYPTO_SUCCESS) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
178 |
ret = KRB5_CRYPTO_INTERNAL; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
179 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
180 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
181 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
182 |
if (!ret) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
183 |
assert(olen == dlen); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
184 |
k5_iov_cursor_put(&cursor, obuf); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
185 |
/* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
186 |
* Updating the ivec arg, if present because of an old/obscure concept |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
187 |
* of cipher state that is being used by only BSD rlogin. See RFCs |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
188 |
* 1391 and 1392 in regards to the vague description of cipher state. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
189 |
* For encrypt/decrypt use the second to the last block of ciphertext |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
190 |
* if > 1 block. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
191 |
*/ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
192 |
if (ivec && ivec->data) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
193 |
unsigned char *bufptr = (op_type == ENCRYPT_OP) ? obuf : dbuf; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
194 |
/* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
195 |
* For encrypt obuf is ciphertext, for decrypt its dbuf which was |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
196 |
* input. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
197 |
*/ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
198 |
memcpy(ivec->data, bufptr + ((dblks - 2) * BLOCK_SIZE), |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
199 |
BLOCK_SIZE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
200 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
201 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
202 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
203 |
zapfree(obuf, olen); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
204 |
zapfree(dbuf, dlen); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
205 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
206 |
return ret; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
207 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
208 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
209 |
krb5_error_code |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
210 |
krb5int_camellia_encrypt(krb5_key key, const krb5_data *ivec, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
211 |
krb5_crypto_iov *data, size_t num_data) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
212 |
{ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
213 |
size_t input_length, nblocks; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
214 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
215 |
input_length = iov_total_length(data, num_data, FALSE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
216 |
nblocks = (input_length + BLOCK_SIZE - 1) / BLOCK_SIZE; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
217 |
if (nblocks == 1) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
218 |
if (input_length != BLOCK_SIZE) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
219 |
return KRB5_BAD_MSIZE; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
220 |
/* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
221 |
* Note, there is bug here (see MIT bug ticket 8551 Crypto providers not |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
222 |
* updating cipher state when 1 block plaintext is encrypted) hence the |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
223 |
* NULL ivec arg. For now we leave the bug in since it has existed in |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
224 |
* MIT code a long time and the tests need the buggy behavior to pass at |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
225 |
* this point. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
226 |
*/ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
227 |
return cbc_docrypt(key, NULL, data, num_data, ENCRYPT_OP); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
228 |
} else { /* nblocks > 1 */ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
229 |
return cts_docrypt(key, ivec, data, num_data, input_length, nblocks, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
230 |
ENCRYPT_OP); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
231 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
232 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
233 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
234 |
krb5_error_code |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
235 |
krb5int_camellia_decrypt(krb5_key key, const krb5_data *ivec, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
236 |
krb5_crypto_iov *data, size_t num_data) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
237 |
{ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
238 |
size_t input_length, nblocks; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
239 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
240 |
input_length = iov_total_length(data, num_data, FALSE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
241 |
nblocks = (input_length + BLOCK_SIZE - 1) / BLOCK_SIZE; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
242 |
if (nblocks == 1) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
243 |
if (input_length != BLOCK_SIZE) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
244 |
return KRB5_BAD_MSIZE; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
245 |
return cbc_docrypt(key, NULL, data, num_data, DECRYPT_OP); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
246 |
} else { /* nblocks > 1 */ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
247 |
return cts_docrypt(key, ivec, data, num_data, input_length, nblocks, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
248 |
DECRYPT_OP); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
249 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
250 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
251 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
252 |
/* |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
253 |
* This function is based on the openssl enc_provider/camellia.c version. |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
254 |
*/ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
255 |
krb5_error_code |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
256 |
krb5int_camellia_cbc_mac(krb5_key key, const krb5_crypto_iov *data, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
257 |
size_t num_data, const krb5_data *ivec, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
258 |
krb5_data *output) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
259 |
{ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
260 |
unsigned char blockY[BLOCK_SIZE], blockB[BLOCK_SIZE]; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
261 |
size_t olen = BLOCK_SIZE; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
262 |
struct iov_cursor cursor; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
263 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
264 |
if (output->length < BLOCK_SIZE) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
265 |
return KRB5_BAD_MSIZE; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
266 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
267 |
if (ivec != NULL && ivec->data != NULL) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
268 |
memcpy(blockY, ivec->data, BLOCK_SIZE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
269 |
else |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
270 |
memset(blockY, 0, BLOCK_SIZE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
271 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
272 |
k5_iov_cursor_init(&cursor, data, num_data, BLOCK_SIZE, FALSE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
273 |
while (k5_iov_cursor_get(&cursor, blockB)) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
274 |
xorblock(blockB, blockY); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
275 |
olen = sizeof(blockY); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
276 |
if (ucrypto_encrypt(CRYPTO_CAMELLIA_ECB, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
277 |
key->keyblock.contents, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
278 |
key->keyblock.length, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
279 |
NULL, 0, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
280 |
blockB, sizeof(blockB), |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
281 |
blockY, &olen) != CRYPTO_SUCCESS) { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
282 |
return KRB5_CRYPTO_INTERNAL; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
283 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
284 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
285 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
286 |
assert(olen == BLOCK_SIZE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
287 |
output->length = BLOCK_SIZE; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
288 |
memcpy(output->data, blockY, BLOCK_SIZE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
289 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
290 |
return 0; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
291 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
292 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
293 |
static krb5_error_code |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
294 |
krb5int_camellia_init_state (const krb5_keyblock *key, krb5_keyusage usage, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
295 |
krb5_data *state) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
296 |
{ |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
297 |
state->data = calloc(1, BLOCK_SIZE); |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
298 |
if (state->data == NULL) |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
299 |
return ENOMEM; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
300 |
state->length = BLOCK_SIZE; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
301 |
return 0; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
302 |
} |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
303 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
304 |
const struct krb5_enc_provider krb5int_enc_camellia128 = { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
305 |
BLOCK_SIZE, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
306 |
16, 16, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
307 |
krb5int_camellia_encrypt, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
308 |
krb5int_camellia_decrypt, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
309 |
krb5int_camellia_cbc_mac, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
310 |
krb5int_camellia_init_state, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
311 |
krb5int_default_free_state |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
312 |
}; |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
313 |
|
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
314 |
const struct krb5_enc_provider krb5int_enc_camellia256 = { |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
315 |
BLOCK_SIZE, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
316 |
32, 32, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
317 |
krb5int_camellia_encrypt, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
318 |
krb5int_camellia_decrypt, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
319 |
krb5int_camellia_cbc_mac, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
320 |
krb5int_camellia_init_state, |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
321 |
krb5int_default_free_state |
50d75ee82dad
25114734 Userland krb should use libucrypto
Will Fiveash <will.fiveash@oracle.com>
parents:
diff
changeset
|
322 |
}; |