Skip to content

Commit b8a7ea5

Browse files
committed
Change return types to bool
1 parent df8bbac commit b8a7ea5

9 files changed

+37
-34
lines changed

src/libmongoc/src/mongoc/mongoc-crypto-cng-private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mongoc_crypto_cng_init (void);
3333
void
3434
mongoc_crypto_cng_cleanup (void);
3535

36-
int
36+
bool
3737
mongoc_crypto_cng_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
3838
const char *password,
3939
size_t password_len,
@@ -58,7 +58,7 @@ mongoc_crypto_cng_sha1 (mongoc_crypto_t *crypto,
5858
const size_t input_len,
5959
unsigned char *hash_out);
6060

61-
int
61+
bool
6262
mongoc_crypto_cng_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
6363
const char *password,
6464
size_t password_len,

src/libmongoc/src/mongoc/mongoc-crypto-cng.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ _crypto_hash_size (mongoc_crypto_t *crypto)
156156

157157
/* Wrapper for BCryptDeriveKeyPBKDF2 */
158158
#if defined(MONGOC_HAVE_BCRYPT_PBKDF2)
159-
static int
159+
static bool
160160
_bcrypt_derive_key_pbkdf2 (BCRYPT_ALG_HANDLE prf,
161161
const char *password,
162162
size_t password_len,
@@ -179,17 +179,19 @@ _bcrypt_derive_key_pbkdf2 (BCRYPT_ALG_HANDLE prf,
179179
output,
180180
output_len,
181181
0);
182+
bson_free (password_copy);
183+
bson_free (salt_copy);
184+
182185
if (!NT_SUCCESS (status)) {
183186
MONGOC_ERROR ("BCryptDeriveKeyPBKDF2(): %ld", status);
187+
return false;
184188
}
185-
bson_free (password_copy);
186-
bson_free (salt_copy);
187-
return (int) status;
189+
return true;
188190
}
189191
#endif
190192

191193
/* Compute the SCRAM step Hi() as defined in RFC5802 */
192-
static void
194+
static bool
193195
mongoc_crypto_cng_derive_key_pbkdf2 (mongoc_crypto_t *crypto,
194196
const char *password,
195197
size_t password_len,
@@ -218,9 +220,10 @@ mongoc_crypto_cng_derive_key_pbkdf2 (mongoc_crypto_t *crypto,
218220
output[k] ^= intermediate_digest[k];
219221
}
220222
}
223+
return true;
221224
}
222225

223-
int
226+
bool
224227
mongoc_crypto_cng_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
225228
const char *password,
226229
size_t password_len,
@@ -234,8 +237,7 @@ mongoc_crypto_cng_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
234237
return _bcrypt_derive_key_pbkdf2 (
235238
_sha1_hmac_algo, password, password_len, salt, salt_len, iterations, output_len, output)
236239
#else
237-
mongoc_crypto_cng_derive_key_pbkdf2 (crypto, password, password_len, salt, salt_len, iterations, output);
238-
return 0;
240+
return mongoc_crypto_cng_derive_key_pbkdf2 (crypto, password, password_len, salt, salt_len, iterations, output);
239241
#endif
240242
}
241243

@@ -270,7 +272,7 @@ mongoc_crypto_cng_sha1 (mongoc_crypto_t *crypto,
270272
return res;
271273
}
272274

273-
int
275+
bool
274276
mongoc_crypto_cng_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
275277
const char *password,
276278
size_t password_len,
@@ -284,8 +286,7 @@ mongoc_crypto_cng_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
284286
return _bcrypt_derive_key_pbkdf2 (
285287
_sha256_hmac_algo, password, password_len, salt, salt_len, iterations, output_len, output)
286288
#else
287-
mongoc_crypto_cng_derive_key_pbkdf2 (crypto, password, password_len, salt, salt_len, iterations, output);
288-
return 0;
289+
return mongoc_crypto_cng_derive_key_pbkdf2 (crypto, password, password_len, salt, salt_len, iterations, output);
289290
#endif
290291
}
291292

src/libmongoc/src/mongoc/mongoc-crypto-common-crypto-private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
BSON_BEGIN_DECLS
2929

30-
int
30+
bool
3131
mongoc_crypto_common_crypto_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
3232
const char *password,
3333
size_t password_len,
@@ -51,7 +51,7 @@ mongoc_crypto_common_crypto_sha1 (mongoc_crypto_t *crypto,
5151
const size_t input_len,
5252
unsigned char *hash_out);
5353

54-
int
54+
bool
5555
mongoc_crypto_common_crypto_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
5656
const char *password,
5757
size_t password_len,

src/libmongoc/src/mongoc/mongoc-crypto-common-crypto.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <CommonCrypto/CommonDigest.h>
2323
#include <CommonCrypto/CommonKeyDerivation.h>
2424

25-
int
25+
bool
2626
mongoc_crypto_common_crypto_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
2727
const char *password,
2828
size_t password_len,
@@ -32,7 +32,7 @@ mongoc_crypto_common_crypto_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
3232
size_t output_len,
3333
unsigned char *output)
3434
{
35-
return CCKeyDerivationPBKDF (
35+
return !CCKeyDerivationPBKDF (
3636
kCCPBKDF2, password, password_len, salt, salt_len, kCCPRFHmacAlgSHA1, iterations, output, output_len);
3737
}
3838

@@ -60,7 +60,7 @@ mongoc_crypto_common_crypto_sha1 (mongoc_crypto_t *crypto,
6060
return false;
6161
}
6262

63-
int
63+
bool
6464
mongoc_crypto_common_crypto_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
6565
const char *password,
6666
size_t password_len,
@@ -70,7 +70,7 @@ mongoc_crypto_common_crypto_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
7070
size_t output_len,
7171
unsigned char *output)
7272
{
73-
return CCKeyDerivationPBKDF (
73+
return !CCKeyDerivationPBKDF (
7474
kCCPBKDF2, password, password_len, salt, salt_len, kCCPRFHmacAlgSHA256, iterations, output, output_len);
7575
}
7676

src/libmongoc/src/mongoc/mongoc-crypto-openssl-private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
BSON_BEGIN_DECLS
3030

31-
int
31+
bool
3232
mongoc_crypto_openssl_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
3333
const char *password,
3434
size_t password_len,
@@ -52,7 +52,7 @@ mongoc_crypto_openssl_sha1 (mongoc_crypto_t *crypto,
5252
const size_t input_len,
5353
unsigned char *hash_out);
5454

55-
int
55+
bool
5656
mongoc_crypto_openssl_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
5757
const char *password,
5858
size_t password_len,

src/libmongoc/src/mongoc/mongoc-crypto-openssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <openssl/evp.h>
2626
#include <openssl/hmac.h>
2727

28-
int
28+
bool
2929
mongoc_crypto_openssl_pbkdf2_hmac_sha1 (mongoc_crypto_t *crypto,
3030
const char *password,
3131
size_t password_len,
@@ -94,7 +94,7 @@ mongoc_crypto_openssl_sha1 (mongoc_crypto_t *crypto,
9494
return rval;
9595
}
9696

97-
int
97+
bool
9898
mongoc_crypto_openssl_pbkdf2_hmac_sha256 (mongoc_crypto_t *crypto,
9999
const char *password,
100100
size_t password_len,

src/libmongoc/src/mongoc/mongoc-crypto-private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct _mongoc_crypto_t {
3939
unsigned char *hmac_out);
4040
bool (*hash) (mongoc_crypto_t *crypto, const unsigned char *input, const size_t input_len, unsigned char *hash_out);
4141

42-
int (*pbkdf) (mongoc_crypto_t *crypto,
42+
bool (*pbkdf) (mongoc_crypto_t *crypto,
4343
const char *password,
4444
size_t password_len,
4545
const uint8_t *salt,

src/libmongoc/src/mongoc/mongoc-crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ mongoc_crypto_init (mongoc_crypto_t *crypto, mongoc_crypto_hash_algorithm_t algo
6969
crypto->algorithm = algo;
7070
}
7171

72-
int
72+
bool
7373
mongoc_crypto_pbkdf (mongoc_crypto_t *crypto,
7474
const char *password,
7575
size_t password_len,

src/libmongoc/src/mongoc/mongoc-scram.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ _mongoc_scram_start (
447447

448448

449449
/* Compute the SCRAM step Hi() as defined in RFC5802 */
450-
static void
450+
static bool
451451
_mongoc_scram_salt_password (mongoc_scram_t *scram,
452452
const char *password,
453453
uint32_t password_len,
@@ -456,7 +456,7 @@ _mongoc_scram_salt_password (mongoc_scram_t *scram,
456456
uint32_t iterations)
457457
{
458458
uint8_t *output = scram->salted_password;
459-
mongoc_crypto_pbkdf (
459+
return mongoc_crypto_pbkdf (
460460
&scram->crypto, password, password_len, salt, salt_len, iterations, MONGOC_SCRAM_HASH_MAX_SIZE, output);
461461
}
462462

@@ -747,13 +747,15 @@ _mongoc_scram_step2 (mongoc_scram_t *scram,
747747
_mongoc_scram_cache_apply_secrets (&cache, scram);
748748
}
749749

750-
if (!*scram->salted_password) {
751-
_mongoc_scram_salt_password (scram,
752-
hashed_password,
753-
(uint32_t) strlen (hashed_password),
754-
decoded_salt,
755-
decoded_salt_len,
756-
(uint32_t) iterations);
750+
if (!*scram->salted_password && !_mongoc_scram_salt_password (scram,
751+
hashed_password,
752+
(uint32_t) strlen (hashed_password),
753+
decoded_salt,
754+
decoded_salt_len,
755+
(uint32_t) iterations)) {
756+
bson_set_error (
757+
error, MONGOC_ERROR_SCRAM, MONGOC_ERROR_SCRAM_PROTOCOL_ERROR, "SCRAM Failure: failed to salt password");
758+
goto FAIL;
757759
}
758760

759761
_mongoc_scram_generate_client_proof (scram, outbuf, outbufmax, outbuflen);

0 commit comments

Comments
 (0)