1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/// @file
#include "jets/q.h"
#include "jets/w.h"
#include "noun.h"
#include "urcrypt.h"
/* All of the CBC hoon truncates its key and prv inputs by passing them to
* the ECB functions, which truncate them, hence the raw u3r_bytes unpacking.
*/
typedef int (*urcrypt_cbc)(c3_y**,
size_t*,
c3_y*,
c3_y*,
urcrypt_realloc_t);
static u3_atom
_cqea_cbc_help(c3_y* key_y, u3_atom iv, u3_atom msg, urcrypt_cbc low_f)
{
u3_atom ret;
c3_w met_w;
c3_y iv_y[16];
c3_y* msg_y = u3r_bytes_all(&met_w, msg);
size_t len = met_w;
u3r_bytes(0, 16, iv_y, iv);
if ( 0 != (*low_f)(&msg_y, &len, key_y, iv_y, &u3a_realloc) ) {
ret = u3_none;
}
else {
ret = u3i_bytes(len, msg_y);
}
u3a_free(msg_y);
return ret;
}
static u3_atom
_cqea_cbca_en(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[16];
u3r_bytes(0, 16, key_y, key);
return _cqea_cbc_help(key_y, iv, msg, &urcrypt_aes_cbca_en);
}
u3_noun
u3wea_cbca_en(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3l_punt("cbca-en", _cqea_cbca_en(a, b, c));
}
}
static u3_atom
_cqea_cbca_de(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[16];
u3r_bytes(0, 16, key_y, key);
return _cqea_cbc_help(key_y, iv, msg, &urcrypt_aes_cbca_de);
}
u3_noun
u3wea_cbca_de(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3l_punt("cbca-de", _cqea_cbca_de(a, b, c));
}
}
static u3_atom
_cqea_cbcb_en(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[24];
u3r_bytes(0, 24, key_y, key);
return _cqea_cbc_help(key_y, iv, msg, &urcrypt_aes_cbcb_en);
}
u3_noun
u3wea_cbcb_en(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3l_punt("cbcb-en", _cqea_cbcb_en(a, b, c));
}
}
static u3_atom
_cqea_cbcb_de(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[24];
u3r_bytes(0, 24, key_y, key);
return _cqea_cbc_help(key_y, iv, msg, &urcrypt_aes_cbcb_de);
}
u3_noun
u3wea_cbcb_de(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3l_punt("cbcb-de", _cqea_cbcb_de(a, b, c));
}
}
static u3_atom
_cqea_cbcc_en(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[32];
u3r_bytes(0, 32, key_y, key);
return _cqea_cbc_help(key_y, iv, msg, &urcrypt_aes_cbcc_en);
}
u3_noun
u3wea_cbcc_en(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3l_punt("cbcc-en", _cqea_cbcc_en(a, b, c));
}
}
static u3_atom
_cqea_cbcc_de(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[32];
u3r_bytes(0, 32, key_y, key);
return _cqea_cbc_help(key_y, iv, msg, &urcrypt_aes_cbcc_de);
}
u3_noun
u3wea_cbcc_de(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3l_punt("cbcc-de", _cqea_cbcc_de(a, b, c));
}
}
|