Commit c3fa6a77 authored by SATOH Fumiyasu's avatar SATOH Fumiyasu Committed by Quanah Gibson-Mount
Browse files

SHA2: Make slapd-sha2 module portable

contrib/slapd-modules/passwd/sha2/sha2.[ch] need portable.h and
some macros to be portable source.

contrib/slapd-modules/passwd/sha2/slapd-sha2.c:hash_sha*() must
declare "struct berval digest" before a statement for K&R C,
and must replace C++ "// foo"-style comments with C style.
parent a74164a9
......@@ -36,11 +36,30 @@
#ifndef __SHA2_H__
#define __SHA2_H__
#include "portable.h"
#ifdef HAVE_INTTYPES_H
# define SHA2_USE_INTTYPES_H 1
#endif
#ifndef LITTLE_ENDIAN
# define LITTLE_ENDIAN 1234
#endif
#ifndef BIG_ENDIAN
# define BIG_ENDIAN 4321
#endif
#ifndef BYTE_ORDER
# ifdef WORDS_BIGENDIAN
# define BYTE_ORDER BIG_ENDIAN
# else
# define BYTE_ORDER LITTLE_ENDIAN
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* Import u_intXX_t size_t type definitions from system headers. You
* may need to change this, or define these things yourself in this
......
......@@ -36,7 +36,7 @@ char * sha256_hex_hash(const char * passwd) {
SHA256_CTX ct;
unsigned char hash[SHA256_DIGEST_LENGTH];
static char real_hash[LUTIL_BASE64_ENCODE_LEN(SHA256_DIGEST_LENGTH)+1]; // extra char for \0
static char real_hash[LUTIL_BASE64_ENCODE_LEN(SHA256_DIGEST_LENGTH)+1]; /* extra char for \0 */
SHA256_Init(&ct);
SHA256_Update(&ct, (const uint8_t*)passwd, strlen(passwd));
......@@ -58,7 +58,7 @@ char * sha384_hex_hash(const char * passwd) {
SHA384_CTX ct;
unsigned char hash[SHA384_DIGEST_LENGTH];
static char real_hash[LUTIL_BASE64_ENCODE_LEN(SHA384_DIGEST_LENGTH)+1]; // extra char for \0
static char real_hash[LUTIL_BASE64_ENCODE_LEN(SHA384_DIGEST_LENGTH)+1]; /* extra char for \0 */
SHA384_Init(&ct);
SHA384_Update(&ct, (const uint8_t*)passwd, strlen(passwd));
......@@ -79,7 +79,7 @@ char * sha512_hex_hash(const char * passwd) {
SHA512_CTX ct;
unsigned char hash[SHA512_DIGEST_LENGTH];
static char real_hash[LUTIL_BASE64_ENCODE_LEN(SHA512_DIGEST_LENGTH)+1]; // extra char for \0
static char real_hash[LUTIL_BASE64_ENCODE_LEN(SHA512_DIGEST_LENGTH)+1]; /* extra char for \0 */
SHA512_Init(&ct);
SHA512_Update(&ct, (const uint8_t*)passwd, strlen(passwd));
......@@ -104,15 +104,14 @@ static int hash_sha256(
{
SHA256_CTX ct;
unsigned char hash256[SHA256_DIGEST_LENGTH];
struct berval digest;
digest.bv_val = (char *) hash256;
digest.bv_len = sizeof(hash256);
SHA256_Init(&ct);
SHA256_Update(&ct, (const uint8_t*)passwd->bv_val, passwd->bv_len);
SHA256_Final(hash256, &ct);
struct berval digest;
digest.bv_val = (char *) hash256;
digest.bv_len = sizeof(hash256);
return lutil_passwd_string64(scheme, &digest, hash, NULL);
}
......@@ -124,6 +123,9 @@ static int hash_sha384(
{
SHA384_CTX ct;
unsigned char hash384[SHA384_DIGEST_LENGTH];
struct berval digest;
digest.bv_val = (char *) hash384;
digest.bv_len = sizeof(hash384);
#ifdef SLAPD_SHA2_DEBUG
fprintf(stderr, "hashing password\n");
......@@ -132,10 +134,6 @@ static int hash_sha384(
SHA384_Update(&ct, (const uint8_t*)passwd->bv_val, passwd->bv_len);
SHA384_Final(hash384, &ct);
struct berval digest;
digest.bv_val = (char *) hash384;
digest.bv_len = sizeof(hash384);
return lutil_passwd_string64(scheme, &digest, hash, NULL);
}
......@@ -147,22 +145,21 @@ static int hash_sha512(
{
SHA512_CTX ct;
unsigned char hash512[SHA512_DIGEST_LENGTH];
struct berval digest;
digest.bv_val = (char *) hash512;
digest.bv_len = sizeof(hash512);
SHA512_Init(&ct);
SHA512_Update(&ct, (const uint8_t*)passwd->bv_val, passwd->bv_len);
SHA512_Final(hash512, &ct);
struct berval digest;
digest.bv_val = (char *) hash512;
digest.bv_len = sizeof(hash512);
return lutil_passwd_string64(scheme, &digest, hash, NULL);
}
static int chk_sha256(
const struct berval *scheme, // Scheme of hashed reference password
const struct berval *passwd, // Hashed reference password to check against
const struct berval *cred, // user-supplied password to check
const struct berval *scheme, /* Scheme of hashed reference password */
const struct berval *passwd, /* Hashed reference password to check against */
const struct berval *cred, /* user-supplied password to check */
const char **text )
{
#ifdef SLAPD_SHA2_DEBUG
......@@ -177,9 +174,9 @@ static int chk_sha256(
}
static int chk_sha384(
const struct berval *scheme, // Scheme of hashed reference password
const struct berval *passwd, // Hashed reference password to check against
const struct berval *cred, // user-supplied password to check
const struct berval *scheme, /* Scheme of hashed reference password */
const struct berval *passwd, /* Hashed reference password to check against */
const struct berval *cred, /* user-supplied password to check */
const char **text )
{
#ifdef SLAPD_SHA2_DEBUG
......@@ -194,9 +191,9 @@ static int chk_sha384(
}
static int chk_sha512(
const struct berval *scheme, // Scheme of hashed reference password
const struct berval *passwd, // Hashed reference password to check against
const struct berval *cred, // user-supplied password to check
const struct berval *scheme, /* Scheme of hashed reference password */
const struct berval *passwd, /* Hashed reference password to check against */
const struct berval *cred, /* user-supplied password to check */
const char **text )
{
#ifdef SLAPD_SHA2_DEBUG
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment