Skip to content

Commit e78f498

Browse files
committed
Refactored for latest version of VaporLibrary
* Updated for VaporLibrary 4.66.1
1 parent 5882001 commit e78f498

File tree

12 files changed

+72
-121
lines changed

12 files changed

+72
-121
lines changed

Package.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.7
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "VaporShell",
88
dependencies: [
9-
9+
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2")
1010
],
1111
targets: [
1212
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
1313
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
1414
.target(name: "CBase32"),
15-
.target(name: "CBcrypt"),
16-
15+
.target(name: "CVaporBcrypt"),
1716
.executableTarget(name: "VaporShell", dependencies: [
17+
.product(name: "Atomics", package: "swift-atomics"),
1818
.target(name: "CBase32"),
19-
.target(name: "CBcrypt")
19+
.target(name: "CVaporBcrypt")
2020
])
2121
]
2222
)

Package.swift.doc

-23
This file was deleted.

Package.swift.dynamic

-22
This file was deleted.

Sources/CBcrypt/include/module.modulemap

-4
This file was deleted.

Sources/CBcrypt/bcrypt.c Sources/CVaporBcrypt/bcrypt.c

+12-13
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@
4242

4343
char *bcrypt_gensalt(u_int8_t);
4444

45-
int encode_base64(char *, const u_int8_t *, size_t);
4645
static int decode_base64(u_int8_t *, size_t, const char *);
4746

4847
/*
4948
* the core bcrypt function
5049
*/
5150
int
52-
bcrypt_hashpass(const char *key, const char *salt, char *encrypted,
53-
size_t encryptedlen)
51+
vapor_bcrypt_hashpass(const char *key, const char *salt, char *encrypted,
52+
size_t encryptedlen)
5453
{
5554
blf_ctx state;
5655
u_int32_t rounds, i, k;
@@ -117,22 +116,22 @@ bcrypt_hashpass(const char *key, const char *salt, char *encrypted,
117116
salt_len = BCRYPT_MAXSALT;
118117

119118
/* Setting up S-Boxes and Subkeys */
120-
Blowfish_initstate(&state);
121-
Blowfish_expandstate(&state, csalt, salt_len,
122-
(u_int8_t *) key, key_len);
119+
Vapor_Blowfish_initstate(&state);
120+
Vapor_Blowfish_expandstate(&state, csalt, salt_len,
121+
(u_int8_t *) key, key_len);
123122
for (k = 0; k < rounds; k++) {
124-
Blowfish_expand0state(&state, (u_int8_t *) key, key_len);
125-
Blowfish_expand0state(&state, csalt, salt_len);
123+
Vapor_Blowfish_expand0state(&state, (u_int8_t *) key, key_len);
124+
Vapor_Blowfish_expand0state(&state, csalt, salt_len);
126125
}
127126

128127
/* This can be precomputed later */
129128
j = 0;
130129
for (i = 0; i < BCRYPT_WORDS; i++)
131-
cdata[i] = Blowfish_stream2word(ciphertext, 4 * BCRYPT_WORDS, &j);
130+
cdata[i] = Vapor_Blowfish_stream2word(ciphertext, 4 * BCRYPT_WORDS, &j);
132131

133132
/* Now do the encryption */
134133
for (k = 0; k < 64; k++)
135-
blf_enc(&state, cdata, BCRYPT_WORDS / 2);
134+
vapor_blf_enc(&state, cdata, BCRYPT_WORDS / 2);
136135

137136
for (i = 0; i < BCRYPT_WORDS; i++) {
138137
ciphertext[4 * i + 3] = cdata[i] & 0xff;
@@ -146,8 +145,8 @@ bcrypt_hashpass(const char *key, const char *salt, char *encrypted,
146145

147146

148147
snprintf(encrypted, 8, "$2%c$%2.2u$", minor, logr);
149-
encode_base64(encrypted + 7, csalt, BCRYPT_MAXSALT);
150-
encode_base64(encrypted + 7 + 22, ciphertext, 4 * BCRYPT_WORDS - 1);
148+
vapor_encode_base64(encrypted + 7, csalt, BCRYPT_MAXSALT);
149+
vapor_encode_base64(encrypted + 7 + 22, ciphertext, 4 * BCRYPT_WORDS - 1);
151150
explicit_bzero(&state, sizeof(state));
152151
explicit_bzero(ciphertext, sizeof(ciphertext));
153152
explicit_bzero(csalt, sizeof(csalt));
@@ -229,7 +228,7 @@ decode_base64(u_int8_t *buffer, size_t len, const char *b64data)
229228
* This works without = padding.
230229
*/
231230
int
232-
encode_base64(char *b64buffer, const u_int8_t *data, size_t len)
231+
vapor_encode_base64(char *b64buffer, const u_int8_t *data, size_t len)
233232
{
234233
u_int8_t *bp = (u_int8_t *)b64buffer;
235234
const u_int8_t *p = data;

Sources/CBcrypt/bcrypt.h Sources/CVaporBcrypt/bcrypt.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ typedef uint64_t u_int64_t;
3535
#define BCRYPT_HASHSPACE 61
3636

3737

38-
int bcrypt_hashpass(const char *key, const char *salt, char *encrypted, size_t encryptedlen);
39-
int encode_base64(char *, const u_int8_t *, size_t);
38+
int vapor_bcrypt_hashpass(const char *key, const char *salt, char *encrypted, size_t encryptedlen);
39+
int vapor_encode_base64(char *, const u_int8_t *, size_t);

Sources/CBcrypt/blf.c Sources/CVaporBcrypt/blf.c

+34-34
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])
6262

6363
void
64-
Blowfish_encipher(blf_ctx *c, u_int32_t *x)
64+
Vapor_Blowfish_encipher(blf_ctx *c, u_int32_t *x)
6565
{
6666
u_int32_t Xl;
6767
u_int32_t Xr;
@@ -86,7 +86,7 @@ Blowfish_encipher(blf_ctx *c, u_int32_t *x)
8686
}
8787

8888
void
89-
Blowfish_decipher(blf_ctx *c, u_int32_t *x)
89+
Vapor_Blowfish_decipher(blf_ctx *c, u_int32_t *x)
9090
{
9191
u_int32_t Xl;
9292
u_int32_t Xr;
@@ -111,7 +111,7 @@ Blowfish_decipher(blf_ctx *c, u_int32_t *x)
111111
}
112112

113113
void
114-
Blowfish_initstate(blf_ctx *c)
114+
Vapor_Blowfish_initstate(blf_ctx *c)
115115
{
116116
/* P-box and S-box tables initialized with digits of Pi */
117117

@@ -391,8 +391,8 @@ Blowfish_initstate(blf_ctx *c)
391391
}
392392

393393
u_int32_t
394-
Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes,
395-
u_int16_t *current)
394+
Vapor_Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes,
395+
u_int16_t *current)
396396
{
397397
u_int8_t i;
398398
u_int16_t j;
@@ -412,7 +412,7 @@ Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes,
412412
}
413413

414414
void
415-
Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes)
415+
Vapor_Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes)
416416
{
417417
u_int16_t i;
418418
u_int16_t j;
@@ -423,23 +423,23 @@ Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes)
423423
j = 0;
424424
for (i = 0; i < BLF_N + 2; i++) {
425425
/* Extract 4 int8 to 1 int32 from keystream */
426-
temp = Blowfish_stream2word(key, keybytes, &j);
426+
temp = Vapor_Blowfish_stream2word(key, keybytes, &j);
427427
c->P[i] = c->P[i] ^ temp;
428428
}
429429

430430
j = 0;
431431
data[0] = 0x00000000;
432432
data[1] = 0x00000000;
433433
for (i = 0; i < BLF_N + 2; i += 2) {
434-
Blowfish_encipher(c, data);
434+
Vapor_Blowfish_encipher(c, data);
435435

436436
c->P[i] = data[0];
437437
c->P[i + 1] = data[1];
438438
}
439439

440440
for (i = 0; i < 4; i++) {
441441
for (k = 0; k < 256; k += 2) {
442-
Blowfish_encipher(c, data);
442+
Vapor_Blowfish_encipher(c, data);
443443

444444
c->S[i][k] = data[0];
445445
c->S[i][k + 1] = data[1];
@@ -449,8 +449,8 @@ Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes)
449449

450450

451451
void
452-
Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
453-
const u_int8_t *key, u_int16_t keybytes)
452+
Vapor_Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
453+
const u_int8_t *key, u_int16_t keybytes)
454454
{
455455
u_int16_t i;
456456
u_int16_t j;
@@ -461,27 +461,27 @@ Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
461461
j = 0;
462462
for (i = 0; i < BLF_N + 2; i++) {
463463
/* Extract 4 int8 to 1 int32 from keystream */
464-
temp = Blowfish_stream2word(key, keybytes, &j);
464+
temp = Vapor_Blowfish_stream2word(key, keybytes, &j);
465465
c->P[i] = c->P[i] ^ temp;
466466
}
467467

468468
j = 0;
469469
d[0] = 0x00000000;
470470
d[1] = 0x00000000;
471471
for (i = 0; i < BLF_N + 2; i += 2) {
472-
d[0] ^= Blowfish_stream2word(data, databytes, &j);
473-
d[1] ^= Blowfish_stream2word(data, databytes, &j);
474-
Blowfish_encipher(c, d);
472+
d[0] ^= Vapor_Blowfish_stream2word(data, databytes, &j);
473+
d[1] ^= Vapor_Blowfish_stream2word(data, databytes, &j);
474+
Vapor_Blowfish_encipher(c, d);
475475

476476
c->P[i] = d[0];
477477
c->P[i + 1] = d[1];
478478
}
479479

480480
for (i = 0; i < 4; i++) {
481481
for (k = 0; k < 256; k += 2) {
482-
d[0]^= Blowfish_stream2word(data, databytes, &j);
483-
d[1] ^= Blowfish_stream2word(data, databytes, &j);
484-
Blowfish_encipher(c, d);
482+
d[0] ^= Vapor_Blowfish_stream2word(data, databytes, &j);
483+
d[1] ^= Vapor_Blowfish_stream2word(data, databytes, &j);
484+
Vapor_Blowfish_encipher(c, d);
485485

486486
c->S[i][k] = d[0];
487487
c->S[i][k + 1] = d[1];
@@ -491,43 +491,43 @@ Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
491491
}
492492

493493
void
494-
blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len)
494+
vapor_blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len)
495495
{
496496
/* Initialize S-boxes and subkeys with Pi */
497-
Blowfish_initstate(c);
497+
Vapor_Blowfish_initstate(c);
498498

499499
/* Transform S-boxes and subkeys with key */
500-
Blowfish_expand0state(c, k, len);
500+
Vapor_Blowfish_expand0state(c, k, len);
501501
}
502502

503503
void
504-
blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
504+
vapor_blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
505505
{
506506
u_int32_t *d;
507507
u_int16_t i;
508508

509509
d = data;
510510
for (i = 0; i < blocks; i++) {
511-
Blowfish_encipher(c, d);
511+
Vapor_Blowfish_encipher(c, d);
512512
d += 2;
513513
}
514514
}
515515

516516
void
517-
blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
517+
vapor_blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
518518
{
519519
u_int32_t *d;
520520
u_int16_t i;
521521

522522
d = data;
523523
for (i = 0; i < blocks; i++) {
524-
Blowfish_decipher(c, d);
524+
Vapor_Blowfish_decipher(c, d);
525525
d += 2;
526526
}
527527
}
528528

529529
void
530-
blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
530+
vapor_blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
531531
{
532532
u_int32_t l, r, d[2];
533533
u_int32_t i;
@@ -537,7 +537,7 @@ blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
537537
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
538538
d[0] = l;
539539
d[1] = r;
540-
Blowfish_encipher(c, d);
540+
Vapor_Blowfish_encipher(c, d);
541541
l = d[0];
542542
r = d[1];
543543
data[0] = l >> 24 & 0xff;
@@ -553,7 +553,7 @@ blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
553553
}
554554

555555
void
556-
blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
556+
vapor_blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
557557
{
558558
u_int32_t l, r, d[2];
559559
u_int32_t i;
@@ -563,7 +563,7 @@ blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
563563
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
564564
d[0] = l;
565565
d[1] = r;
566-
Blowfish_decipher(c, d);
566+
Vapor_Blowfish_decipher(c, d);
567567
l = d[0];
568568
r = d[1];
569569
data[0] = l >> 24 & 0xff;
@@ -579,7 +579,7 @@ blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
579579
}
580580

581581
void
582-
blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
582+
vapor_blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
583583
{
584584
u_int32_t l, r, d[2];
585585
u_int32_t i, j;
@@ -591,7 +591,7 @@ blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
591591
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
592592
d[0] = l;
593593
d[1] = r;
594-
Blowfish_encipher(c, d);
594+
Vapor_Blowfish_encipher(c, d);
595595
l = d[0];
596596
r = d[1];
597597
data[0] = l >> 24 & 0xff;
@@ -608,7 +608,7 @@ blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
608608
}
609609

610610
void
611-
blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
611+
vapor_blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
612612
{
613613
u_int32_t l, r, d[2];
614614
u_int8_t *iv;
@@ -621,7 +621,7 @@ blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
621621
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
622622
d[0] = l;
623623
d[1] = r;
624-
Blowfish_decipher(c, d);
624+
Vapor_Blowfish_decipher(c, d);
625625
l = d[0];
626626
r = d[1];
627627
data[0] = l >> 24 & 0xff;
@@ -641,7 +641,7 @@ blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
641641
r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
642642
d[0] = l;
643643
d[1] = r;
644-
Blowfish_decipher(c, d);
644+
Vapor_Blowfish_decipher(c, d);
645645
l = d[0];
646646
r = d[1];
647647
data[0] = l >> 24 & 0xff;

0 commit comments

Comments
 (0)