Skip to content

Commit

Permalink
refactor: replace be32enc with WriteBE32
Browse files Browse the repository at this point in the history
be32enc is a function on BSDs which can lead to conflicts. Use the
WriteBE32 function that's used in crypto code instead.
  • Loading branch information
div72 committed Jul 15, 2024
1 parent 156f0fc commit 128035d
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions src/pbkdf2.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
// Copyright (c) 2013 NovaCoin Developers

#include <string.h>
#include "pbkdf2.h"

// Only commented out since it will be used in Big endian support
// in the future.
/*
static inline uint32_t
be32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
}
*/
#include <crypto/common.h>
#include <pbkdf2.h>

#ifndef __FreeBSD__
static inline void
be32enc(void *pp, uint32_t x)
{
uint8_t * p = (uint8_t *)pp;
#include <string.h>

p[3] = x & 0xff;
p[2] = (x >> 8) & 0xff;
p[1] = (x >> 16) & 0xff;
p[0] = (x >> 24) & 0xff;
}
#endif

/**
* PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen):
Expand All @@ -54,7 +31,7 @@ PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt,
/* Iterate through the blocks. */
for (i = 0; i * 32 < dkLen; i++) {
/* Generate INT(i + 1). */
be32enc(ivec, (uint32_t)(i + 1));
WriteBE32(ivec, (uint32_t)(i + 1));

/* Compute U_1 = PRF(P, S || INT(i)). */
CHMAC_SHA256 U_1 = salted;
Expand Down

0 comments on commit 128035d

Please sign in to comment.