2017-08-23 05:09:07 +03:00
|
|
|
// Copyright (c) 2017-present, Facebook, Inc.
|
|
|
|
// All Rights Reserved.
|
|
|
|
//
|
|
|
|
// This software may be used and distributed according to the terms of the
|
|
|
|
// GNU General Public License version 2 or any later version.
|
|
|
|
|
|
|
|
// sha1.h - wrapper functions around the underlying SHA-1 implementation.
|
|
|
|
//
|
|
|
|
// no-check-code
|
2017-08-26 02:46:07 +03:00
|
|
|
#ifndef FBHGEXT_CLIB_SHA1_H
|
|
|
|
#define FBHGEXT_CLIB_SHA1_H
|
2017-08-23 05:09:07 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-08-23 05:09:07 +03:00
|
|
|
#ifdef SHA1_USE_SHA1DC
|
2018-01-09 04:55:53 +03:00
|
|
|
#include <lib/third-party/sha1dc/sha1.h>
|
2018-06-06 05:20:17 +03:00
|
|
|
#include <stdlib.h>
|
2017-08-23 05:09:07 +03:00
|
|
|
|
|
|
|
typedef SHA1_CTX fbhg_sha1_ctx_t;
|
|
|
|
|
|
|
|
static inline int fbhg_sha1_init(fbhg_sha1_ctx_t* ctx) {
|
|
|
|
SHA1DCInit(ctx);
|
2017-08-23 05:09:07 +03:00
|
|
|
SHA1DCSetSafeHash(ctx, 0);
|
|
|
|
SHA1DCSetUseDetectColl(ctx, 0);
|
2017-08-23 05:09:07 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
fbhg_sha1_update(fbhg_sha1_ctx_t* ctx, const void* data, unsigned long length) {
|
2017-08-23 05:09:07 +03:00
|
|
|
SHA1DCUpdate(ctx, (const char*)data, length);
|
2017-08-23 05:09:07 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int fbhg_sha1_final(unsigned char* md, fbhg_sha1_ctx_t* ctx) {
|
|
|
|
return SHA1DCFinal(md, ctx);
|
|
|
|
}
|
2017-08-23 05:09:07 +03:00
|
|
|
#else
|
|
|
|
#include <openssl/sha.h>
|
|
|
|
|
|
|
|
typedef SHA_CTX fbhg_sha1_ctx_t;
|
|
|
|
|
|
|
|
static inline int fbhg_sha1_init(fbhg_sha1_ctx_t* ctx) {
|
|
|
|
return SHA1_Init(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
fbhg_sha1_update(fbhg_sha1_ctx_t* ctx, const void* data, unsigned long length) {
|
|
|
|
return SHA1_Update(ctx, data, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int fbhg_sha1_final(unsigned char* md, fbhg_sha1_ctx_t* ctx) {
|
|
|
|
return SHA1_Final(md, ctx);
|
|
|
|
}
|
|
|
|
#endif
|
2017-08-23 05:09:07 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern C */
|
|
|
|
#endif
|
2017-08-26 02:46:07 +03:00
|
|
|
|
|
|
|
#endif /* FBHGEXT_CLIB_SHA1_H */
|