summaryrefslogtreecommitdiff
path: root/libs/libssh2/src/bcrypt_pbkdf.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libssh2/src/bcrypt_pbkdf.c')
-rw-r--r--libs/libssh2/src/bcrypt_pbkdf.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/libs/libssh2/src/bcrypt_pbkdf.c b/libs/libssh2/src/bcrypt_pbkdf.c
index d088587873..414c5e4e36 100644
--- a/libs/libssh2/src/bcrypt_pbkdf.c
+++ b/libs/libssh2/src/bcrypt_pbkdf.c
@@ -127,9 +127,12 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt,
memcpy(countsalt, salt, saltlen);
/* collapse password */
- (void)libssh2_sha512_init(&ctx);
- libssh2_sha512_update(ctx, pass, passlen);
- libssh2_sha512_final(ctx, sha2pass);
+ if(!libssh2_sha512_init(&ctx) ||
+ !libssh2_sha512_update(ctx, pass, passlen) ||
+ !libssh2_sha512_final(ctx, sha2pass)) {
+ free(countsalt);
+ return -1;
+ }
/* generate key, sizeof(out) at a time */
for(count = 1; keylen > 0; count++) {
@@ -139,18 +142,26 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt,
countsalt[saltlen + 3] = count & 0xff;
/* first round, salt is salt */
- (void)libssh2_sha512_init(&ctx);
- libssh2_sha512_update(ctx, countsalt, saltlen + 4);
- libssh2_sha512_final(ctx, sha2salt);
+ if(!libssh2_sha512_init(&ctx) ||
+ !libssh2_sha512_update(ctx, countsalt, saltlen + 4) ||
+ !libssh2_sha512_final(ctx, sha2salt)) {
+ _libssh2_explicit_zero(out, sizeof(out));
+ free(countsalt);
+ return -1;
+ }
bcrypt_hash(sha2pass, sha2salt, tmpout);
memcpy(out, tmpout, sizeof(out));
for(i = 1; i < rounds; i++) {
/* subsequent rounds, salt is previous output */
- (void)libssh2_sha512_init(&ctx);
- libssh2_sha512_update(ctx, tmpout, sizeof(tmpout));
- libssh2_sha512_final(ctx, sha2salt);
+ if(!libssh2_sha512_init(&ctx) ||
+ !libssh2_sha512_update(ctx, tmpout, sizeof(tmpout)) ||
+ !libssh2_sha512_final(ctx, sha2salt)) {
+ _libssh2_explicit_zero(out, sizeof(out));
+ free(countsalt);
+ return -1;
+ }
bcrypt_hash(sha2pass, sha2salt, tmpout);
for(j = 0; j < sizeof(out); j++)