summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Sebastian Battig <jsbattig@convey.com>2014-09-16 17:47:26 -0500
committerJose Sebastian Battig <jsbattig@convey.com>2014-09-16 17:47:26 -0500
commit7894d848087e84d4011f392c3e91a603800ab36b (patch)
tree08d06c123385373a83700e0d01708f3b438dfa46
parentc75e52cc1219ff79947078772fc5c0543cbeee8b (diff)
B-0 modifications made to allow compilation in Visual Studio
-rw-r--r--b64.c2
-rw-r--r--crypto-mcf.c10
-rw-r--r--crypto-scrypt-saltgen.c4
-rw-r--r--libscrypt.h9
-rw-r--r--sysendian.h21
5 files changed, 31 insertions, 15 deletions
diff --git a/b64.c b/b64.c
index 0e8c221..b797dd0 100644
--- a/b64.c
+++ b/b64.c
@@ -174,7 +174,7 @@ libscrypt_b64_encode(src, srclength, target, targsize)
if (datalength >= targsize)
return (-1);
target[datalength] = '\0'; /* Returned value doesn't count \0. */
- return (datalength);
+ return (int)(datalength);
}
/* skips all whitespace anywhere.
diff --git a/crypto-mcf.c b/crypto-mcf.c
index 74e7be0..8ad3eb8 100644
--- a/crypto-mcf.c
+++ b/crypto-mcf.c
@@ -25,13 +25,19 @@ static uint32_t scrypt_ilog2(uint32_t n)
while (((uint32_t)1 << t) < n)
{
if(t > SCRYPT_SAFE_N)
- return -1; /* Check for insanity */
+ return (uint32_t) -1; /* Check for insanity */
t++;
}
return t;
}
+#ifdef _MSC_VER
+ #define SNPRINTF _snprintf
+#else
+ #define SNPRINTF snprintf
+#endif
+
int libscrypt_mcf(uint32_t N, uint32_t r, uint32_t p, const char *salt,
const char *hash, char *mcf)
{
@@ -59,7 +65,7 @@ int libscrypt_mcf(uint32_t N, uint32_t r, uint32_t p, const char *salt,
* determined that mcf should be defined as at least SCRYPT_MCF_LEN
* in length
*/
- s = snprintf(mcf, SCRYPT_MCF_LEN, SCRYPT_MCF_ID "$%06x$%s$%s", (unsigned int)params, salt, hash);
+ s = SNPRINTF(mcf, SCRYPT_MCF_LEN, SCRYPT_MCF_ID "$%06x$%s$%s", (unsigned int)params, salt, hash);
if (s > SCRYPT_MCF_LEN)
return 0;
diff --git a/crypto-scrypt-saltgen.c b/crypto-scrypt-saltgen.c
index a0e2998..beded9c 100644
--- a/crypto-scrypt-saltgen.c
+++ b/crypto-scrypt-saltgen.c
@@ -8,6 +8,8 @@
#include <unistd.h>
#endif
+#ifndef _MSC_VER
+
#define RNGDEV "/dev/urandom"
int libscrypt_salt_gen(uint8_t *salt, size_t len)
@@ -46,3 +48,5 @@ int libscrypt_salt_gen(uint8_t *salt, size_t len)
return 0;
}
+
+#endif
diff --git a/libscrypt.h b/libscrypt.h
index 318576e..b7141f5 100644
--- a/libscrypt.h
+++ b/libscrypt.h
@@ -33,18 +33,19 @@ int libscrypt_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, uint64_t,
int libscrypt_mcf(uint32_t N, uint32_t r, uint32_t p, const char *salt,
const char *hash, char *mcf);
+#ifndef _MSC_VER
/* Generates a salt. Uses /dev/urandom/
*/
int libscrypt_salt_gen(/*@out@*/ uint8_t *rand, size_t len);
-/* Checks a given MCF against a password */
-int libscrypt_check(char *mcf, const char *password);
-
/* Creates a hash of a passphrase using a randomly generated salt */
/* Returns >0 on success, or 0 for fail */
int libscrypt_hash(char *dst, const char* passphrase, uint32_t N, uint8_t r,
- uint8_t p);
+ uint8_t p);
+#endif
+/* Checks a given MCF against a password */
+int libscrypt_check(char *mcf, const char *password);
#ifdef __cplusplus
}
diff --git a/sysendian.h b/sysendian.h
index 5ecb505..af1ecdc 100644
--- a/sysendian.h
+++ b/sysendian.h
@@ -42,8 +42,13 @@
#else
#include <stdint.h>
+#ifdef _MSC_VER
+ #define INLINE __inline
+#else
+ #define INLINE inline
+#endif
-static inline uint32_t
+static INLINE uint32_t
be32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
@@ -52,7 +57,7 @@ be32dec(const void *pp)
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
}
-static inline void
+static INLINE void
be32enc(void *pp, uint32_t x)
{
uint8_t * p = (uint8_t *)pp;
@@ -63,7 +68,7 @@ be32enc(void *pp, uint32_t x)
p[0] = (x >> 24) & 0xff;
}
-static inline uint64_t
+static INLINE uint64_t
be64dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
@@ -74,7 +79,7 @@ be64dec(const void *pp)
((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56));
}
-static inline void
+static INLINE void
be64enc(void *pp, uint64_t x)
{
uint8_t * p = (uint8_t *)pp;
@@ -89,7 +94,7 @@ be64enc(void *pp, uint64_t x)
p[0] = (x >> 56) & 0xff;
}
-static inline uint32_t
+static INLINE uint32_t
le32dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
@@ -98,7 +103,7 @@ le32dec(const void *pp)
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
}
-static inline void
+static INLINE void
le32enc(void *pp, uint32_t x)
{
uint8_t * p = (uint8_t *)pp;
@@ -109,7 +114,7 @@ le32enc(void *pp, uint32_t x)
p[3] = (x >> 24) & 0xff;
}
-static inline uint64_t
+static INLINE uint64_t
le64dec(const void *pp)
{
const uint8_t *p = (uint8_t const *)pp;
@@ -120,7 +125,7 @@ le64dec(const void *pp)
((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56));
}
-static inline void
+static INLINE void
le64enc(void *pp, uint64_t x)
{
uint8_t * p = (uint8_t *)pp;