Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1029)

Side by Side Diff: fusl/src/crypt/encrypt.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/crypt/crypt_sha512.c ('k') | fusl/src/ctype/__ctype_b_loc.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 struct expanded_key {
6 uint32_t l[16], r[16];
7 };
8
9 void __des_setkey(const unsigned char *key, struct expanded_key *ekey);
10 void __do_des(uint32_t l_in, uint32_t r_in,
11 uint32_t *l_out, uint32_t *r_out,
12 uint32_t count, uint32_t saltbits, const struct expanded_key *ekey);
13
14
15 static struct expanded_key __encrypt_key;
16
17 void setkey(const char *key)
18 {
19 unsigned char bkey[8];
20 int i, j;
21
22 for (i = 0; i < 8; i++) {
23 bkey[i] = 0;
24 for (j = 7; j >= 0; j--, key++)
25 bkey[i] |= (uint32_t)(*key & 1) << j;
26 }
27
28 __des_setkey(bkey, &__encrypt_key);
29 }
30
31 void encrypt(char *block, int edflag)
32 {
33 struct expanded_key decrypt_key, *key;
34 uint32_t b[2];
35 int i, j;
36 char *p;
37
38 p = block;
39 for (i = 0; i < 2; i++) {
40 b[i] = 0;
41 for (j = 31; j >= 0; j--, p++)
42 b[i] |= (uint32_t)(*p & 1) << j;
43 }
44
45 key = &__encrypt_key;
46 if (edflag) {
47 key = &decrypt_key;
48 for (i = 0; i < 16; i++) {
49 decrypt_key.l[i] = __encrypt_key.l[15-i];
50 decrypt_key.r[i] = __encrypt_key.r[15-i];
51 }
52 }
53
54 __do_des(b[0], b[1], b, b + 1, 1, 0, key);
55
56 p = block;
57 for (i = 0; i < 2; i++)
58 for (j = 31; j >= 0; j--)
59 *p++ = b[i]>>j & 1;
60 }
OLDNEW
« no previous file with comments | « fusl/src/crypt/crypt_sha512.c ('k') | fusl/src/ctype/__ctype_b_loc.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698