Skip to content

Commit aae110a

Browse files
authored
Merge pull request #1
- C interface prefix rename from vapor to bb
2 parents f1b8829 + f4f0088 commit aae110a

File tree

5 files changed

+65
-65
lines changed

5 files changed

+65
-65
lines changed

Sources/Bcrypt/BCrypt.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ extension Collection where Element: Equatable {
6969
///
7070
/// Use BCrypt to create hashes for sensitive information like passwords.
7171
///
72-
/// try BCrypt.hash("vapor", cost: 4)
72+
/// try BCrypt.hash("binary_birds", cost: 4)
7373
///
7474
/// BCrypt uses a random salt each time it creates a hash. To verify hashes, use the `verify(_:matches)` method.
7575
///
76-
/// let hash = try BCrypt.hash("vapor", cost: 4)
77-
/// try BCrypt.verify("vapor", created: hash) // true
76+
/// let hash = try BCrypt.hash("binary_birds", cost: 4)
77+
/// try BCrypt.verify("binary_birds", created: hash) // true
7878
///
7979
/// https://en.wikipedia.org/wiki/Bcrypt
8080
public var Bcrypt: BCryptDigest {
@@ -84,7 +84,7 @@ public var Bcrypt: BCryptDigest {
8484
/// Creates and verifies BCrypt hashes. Normally you will not need to initialize one of these classes and you will
8585
/// use the global `BCrypt` convenience instead.
8686
///
87-
/// try BCrypt.hash("vapor", cost: 4)
87+
/// try BCrypt.hash("binary_birds", cost: 4)
8888
///
8989
/// See `BCrypt` for more information.
9090
public final class BCryptDigest {
@@ -134,7 +134,7 @@ public final class BCryptDigest {
134134

135135
let hashedBytes = UnsafeMutablePointer<Int8>.allocate(capacity: 128)
136136
defer { hashedBytes.deallocate() }
137-
let hashingResult = vapor_bcrypt_hashpass(
137+
let hashingResult = bb_bcrypt_hashpass(
138138
plaintext,
139139
normalizedSalt,
140140
hashedBytes,
@@ -152,8 +152,8 @@ public final class BCryptDigest {
152152
/// Verifies an existing BCrypt hash matches the supplied plaintext value. Verification works by parsing the salt and version from
153153
/// the existing digest and using that information to hash the plaintext data. If hash digests match, this method returns `true`.
154154
///
155-
/// let hash = try BCrypt.hash("vapor", cost: 4)
156-
/// try BCrypt.verify("vapor", created: hash) // true
155+
/// let hash = try BCrypt.hash("binary_birds", cost: 4)
156+
/// try BCrypt.verify("binary_birds", created: hash) // true
157157
/// try BCrypt.verify("foo", created: hash) // false
158158
///
159159
/// - parameters:
@@ -247,7 +247,7 @@ public final class BCryptDigest {
247247
let encodedBytes = UnsafeMutablePointer<Int8>.allocate(capacity: 25)
248248
defer { encodedBytes.deallocate() }
249249
let res = data.withUnsafeBytes { bytes in
250-
vapor_encode_base64(
250+
bb_encode_base64(
251251
encodedBytes,
252252
bytes.baseAddress?.assumingMemoryBound(to: UInt8.self),
253253
bytes.count

Sources/CBcrypt/bcrypt.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static int decode_base64(u_int8_t *, size_t, const char *);
4848
* the core bcrypt function
4949
*/
5050
int
51-
vapor_bcrypt_hashpass(const char *key, const char *salt, char *encrypted,
51+
bb_bcrypt_hashpass(const char *key, const char *salt, char *encrypted,
5252
size_t encryptedlen)
5353
{
5454
blf_ctx state;
@@ -116,22 +116,22 @@ vapor_bcrypt_hashpass(const char *key, const char *salt, char *encrypted,
116116
salt_len = BCRYPT_MAXSALT;
117117

118118
/* Setting up S-Boxes and Subkeys */
119-
Vapor_Blowfish_initstate(&state);
120-
Vapor_Blowfish_expandstate(&state, csalt, salt_len,
119+
BB_Blowfish_initstate(&state);
120+
BB_Blowfish_expandstate(&state, csalt, salt_len,
121121
(u_int8_t *) key, key_len);
122122
for (k = 0; k < rounds; k++) {
123-
Vapor_Blowfish_expand0state(&state, (u_int8_t *) key, key_len);
124-
Vapor_Blowfish_expand0state(&state, csalt, salt_len);
123+
BB_Blowfish_expand0state(&state, (u_int8_t *) key, key_len);
124+
BB_Blowfish_expand0state(&state, csalt, salt_len);
125125
}
126126

127127
/* This can be precomputed later */
128128
j = 0;
129129
for (i = 0; i < BCRYPT_WORDS; i++)
130-
cdata[i] = Vapor_Blowfish_stream2word(ciphertext, 4 * BCRYPT_WORDS, &j);
130+
cdata[i] = BB_Blowfish_stream2word(ciphertext, 4 * BCRYPT_WORDS, &j);
131131

132132
/* Now do the encryption */
133133
for (k = 0; k < 64; k++)
134-
vapor_blf_enc(&state, cdata, BCRYPT_WORDS / 2);
134+
bb_blf_enc(&state, cdata, BCRYPT_WORDS / 2);
135135

136136
for (i = 0; i < BCRYPT_WORDS; i++) {
137137
ciphertext[4 * i + 3] = cdata[i] & 0xff;
@@ -145,8 +145,8 @@ vapor_bcrypt_hashpass(const char *key, const char *salt, char *encrypted,
145145

146146

147147
snprintf(encrypted, 8, "$2%c$%2.2u$", minor, logr);
148-
vapor_encode_base64(encrypted + 7, csalt, BCRYPT_MAXSALT);
149-
vapor_encode_base64(encrypted + 7 + 22, ciphertext, 4 * BCRYPT_WORDS - 1);
148+
bb_encode_base64(encrypted + 7, csalt, BCRYPT_MAXSALT);
149+
bb_encode_base64(encrypted + 7 + 22, ciphertext, 4 * BCRYPT_WORDS - 1);
150150
explicit_bzero(&state, sizeof(state));
151151
explicit_bzero(ciphertext, sizeof(ciphertext));
152152
explicit_bzero(csalt, sizeof(csalt));
@@ -228,7 +228,7 @@ decode_base64(u_int8_t *buffer, size_t len, const char *b64data)
228228
* This works without = padding.
229229
*/
230230
int
231-
vapor_encode_base64(char *b64buffer, const u_int8_t *data, size_t len)
231+
bb_encode_base64(char *b64buffer, const u_int8_t *data, size_t len)
232232
{
233233
u_int8_t *bp = (u_int8_t *)b64buffer;
234234
const u_int8_t *p = data;

Sources/CBcrypt/bcrypt.h

Lines changed: 2 additions & 2 deletions
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 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);
38+
int bb_bcrypt_hashpass(const char *key, const char *salt, char *encrypted, size_t encryptedlen);
39+
int bb_encode_base64(char *, const u_int8_t *, size_t);

Sources/CBcrypt/blf.c

Lines changed: 32 additions & 32 deletions
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-
Vapor_Blowfish_encipher(blf_ctx *c, u_int32_t *x)
64+
BB_Blowfish_encipher(blf_ctx *c, u_int32_t *x)
6565
{
6666
u_int32_t Xl;
6767
u_int32_t Xr;
@@ -86,7 +86,7 @@ Vapor_Blowfish_encipher(blf_ctx *c, u_int32_t *x)
8686
}
8787

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

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

@@ -391,7 +391,7 @@ Vapor_Blowfish_initstate(blf_ctx *c)
391391
}
392392

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

414414
void
415-
Vapor_Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes)
415+
BB_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 @@ Vapor_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 = Vapor_Blowfish_stream2word(key, keybytes, &j);
426+
temp = BB_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-
Vapor_Blowfish_encipher(c, data);
434+
BB_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-
Vapor_Blowfish_encipher(c, data);
442+
BB_Blowfish_encipher(c, data);
443443

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

450450

451451
void
452-
Vapor_Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
452+
BB_Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
453453
const u_int8_t *key, u_int16_t keybytes)
454454
{
455455
u_int16_t i;
@@ -461,27 +461,27 @@ Vapor_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 = Vapor_Blowfish_stream2word(key, keybytes, &j);
464+
temp = BB_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] ^= Vapor_Blowfish_stream2word(data, databytes, &j);
473-
d[1] ^= Vapor_Blowfish_stream2word(data, databytes, &j);
474-
Vapor_Blowfish_encipher(c, d);
472+
d[0] ^= BB_Blowfish_stream2word(data, databytes, &j);
473+
d[1] ^= BB_Blowfish_stream2word(data, databytes, &j);
474+
BB_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] ^= Vapor_Blowfish_stream2word(data, databytes, &j);
483-
d[1] ^= Vapor_Blowfish_stream2word(data, databytes, &j);
484-
Vapor_Blowfish_encipher(c, d);
482+
d[0] ^= BB_Blowfish_stream2word(data, databytes, &j);
483+
d[1] ^= BB_Blowfish_stream2word(data, databytes, &j);
484+
BB_Blowfish_encipher(c, d);
485485

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

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

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

503503
void
504-
vapor_blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
504+
bb_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-
Vapor_Blowfish_encipher(c, d);
511+
BB_Blowfish_encipher(c, d);
512512
d += 2;
513513
}
514514
}
515515

516516
void
517-
vapor_blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
517+
bb_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-
Vapor_Blowfish_decipher(c, d);
524+
BB_Blowfish_decipher(c, d);
525525
d += 2;
526526
}
527527
}
528528

529529
void
530-
vapor_blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
530+
bb_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 @@ vapor_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-
Vapor_Blowfish_encipher(c, d);
540+
BB_Blowfish_encipher(c, d);
541541
l = d[0];
542542
r = d[1];
543543
data[0] = l >> 24 & 0xff;
@@ -553,7 +553,7 @@ vapor_blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
553553
}
554554

555555
void
556-
vapor_blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
556+
bb_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 @@ vapor_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-
Vapor_Blowfish_decipher(c, d);
566+
BB_Blowfish_decipher(c, d);
567567
l = d[0];
568568
r = d[1];
569569
data[0] = l >> 24 & 0xff;
@@ -579,7 +579,7 @@ vapor_blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
579579
}
580580

581581
void
582-
vapor_blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
582+
bb_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 @@ vapor_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-
Vapor_Blowfish_encipher(c, d);
594+
BB_Blowfish_encipher(c, d);
595595
l = d[0];
596596
r = d[1];
597597
data[0] = l >> 24 & 0xff;
@@ -608,7 +608,7 @@ vapor_blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
608608
}
609609

610610
void
611-
vapor_blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
611+
bb_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 @@ vapor_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-
Vapor_Blowfish_decipher(c, d);
624+
BB_Blowfish_decipher(c, d);
625625
l = d[0];
626626
r = d[1];
627627
data[0] = l >> 24 & 0xff;
@@ -641,7 +641,7 @@ vapor_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-
Vapor_Blowfish_decipher(c, d);
644+
BB_Blowfish_decipher(c, d);
645645
l = d[0];
646646
r = d[1];
647647
data[0] = l >> 24 & 0xff;

Sources/CBcrypt/blf.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@ typedef struct BlowfishContext {
6060
* Blowfish_expand0state( state, key, keylen )
6161
*/
6262

63-
void Vapor_Blowfish_encipher(blf_ctx *, u_int32_t *);
64-
void Vapor_Blowfish_decipher(blf_ctx *, u_int32_t *);
65-
void Vapor_Blowfish_initstate(blf_ctx *);
66-
void Vapor_Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t);
67-
void Vapor_Blowfish_expandstate(blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t);
63+
void BB_Blowfish_encipher(blf_ctx *, u_int32_t *);
64+
void BB_Blowfish_decipher(blf_ctx *, u_int32_t *);
65+
void BB_Blowfish_initstate(blf_ctx *);
66+
void BB_Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t);
67+
void BB_Blowfish_expandstate(blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t);
6868

6969
/* Standard Blowfish */
7070

71-
void vapor_blf_key(blf_ctx *, const u_int8_t *, u_int16_t);
72-
void vapor_blf_enc(blf_ctx *, u_int32_t *, u_int16_t);
73-
void vapor_blf_dec(blf_ctx *, u_int32_t *, u_int16_t);
71+
void bb_blf_key(blf_ctx *, const u_int8_t *, u_int16_t);
72+
void bb_blf_enc(blf_ctx *, u_int32_t *, u_int16_t);
73+
void bb_blf_dec(blf_ctx *, u_int32_t *, u_int16_t);
7474

7575
/* Converts u_int8_t to u_int32_t */
76-
u_int32_t Vapor_Blowfish_stream2word(const u_int8_t *, u_int16_t ,
76+
u_int32_t BB_Blowfish_stream2word(const u_int8_t *, u_int16_t ,
7777
u_int16_t *);
7878

79-
void vapor_blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t);
80-
void vapor_blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t);
79+
void bb_blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t);
80+
void bb_blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t);
8181

82-
void vapor_blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
83-
void vapor_blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
82+
void bb_blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
83+
void bb_blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
8484
#endif

0 commit comments

Comments
 (0)