mirror of
https://codeberg.org/guix/guix.git
synced 2025-10-02 02:15:12 +00:00
daemon: Remove OpenSSL hash compatibility wrappers.
* nix/libutil/hash.cc (struct Ctx): Copy from gcrypt-hash.hh. (start, update, finish): Use gcrypt functions directly instead of OpenSSL-like wrappers. * nix/libutil/gcrypt-hash.cc, nix/libutil/gcrypt-hash.hh, nix/libutil/md5.h, nix/libutil/sha1.h, nix/libutil/sha256.h, nix/libutil/sha512.h: Remove. * nix/local.mk (libutil_a_SOURCES, libutil_headers): Adjust accordingly.
This commit is contained in:
parent
3fb6b8f304
commit
8dc6c38785
8 changed files with 27 additions and 279 deletions
|
@ -3,18 +3,6 @@
|
|||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
#include <openssl/md5.h>
|
||||
#include <openssl/sha.h>
|
||||
#else
|
||||
extern "C" {
|
||||
#include "md5.h"
|
||||
#include "sha1.h"
|
||||
#include "sha256.h"
|
||||
#include "sha512.h"
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "hash.hh"
|
||||
#include "archive.hh"
|
||||
#include "util.hh"
|
||||
|
@ -193,41 +181,48 @@ bool isHash(const string & s)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* The "hash context". */
|
||||
struct Ctx
|
||||
{
|
||||
MD5_CTX md5;
|
||||
SHA_CTX sha1;
|
||||
SHA256_CTX sha256;
|
||||
SHA512_CTX sha512;
|
||||
/* This copy constructor is needed in 'HashSink::currentHash()' where we
|
||||
expect the copy of a 'Ctx' object to yield a truly different context. */
|
||||
Ctx(Ctx &ref)
|
||||
{
|
||||
if (ref.md_handle == NULL)
|
||||
md_handle = NULL;
|
||||
else
|
||||
gcry_md_copy (&md_handle, ref.md_handle);
|
||||
}
|
||||
|
||||
/* Make sure 'md_handle' is always initialized. */
|
||||
Ctx(): md_handle (NULL) { };
|
||||
|
||||
gcry_md_hd_t md_handle;
|
||||
};
|
||||
|
||||
|
||||
static void start(HashType ht, Ctx & ctx)
|
||||
{
|
||||
if (ht == htMD5) MD5_Init(&ctx.md5);
|
||||
else if (ht == htSHA1) SHA1_Init(&ctx.sha1);
|
||||
else if (ht == htSHA256) SHA256_Init(&ctx.sha256);
|
||||
else if (ht == htSHA512) SHA512_Init(&ctx.sha512);
|
||||
gcry_error_t err;
|
||||
|
||||
err = gcry_md_open (&ctx.md_handle, ht, 0);
|
||||
assert (err == GPG_ERR_NO_ERROR);
|
||||
}
|
||||
|
||||
|
||||
static void update(HashType ht, Ctx & ctx,
|
||||
const unsigned char * bytes, unsigned int len)
|
||||
{
|
||||
if (ht == htMD5) MD5_Update(&ctx.md5, bytes, len);
|
||||
else if (ht == htSHA1) SHA1_Update(&ctx.sha1, bytes, len);
|
||||
else if (ht == htSHA256) SHA256_Update(&ctx.sha256, bytes, len);
|
||||
else if (ht == htSHA512) SHA512_Update(&ctx.sha512, bytes, len);
|
||||
gcry_md_write (ctx.md_handle, bytes, len);
|
||||
}
|
||||
|
||||
|
||||
static void finish(HashType ht, Ctx & ctx, unsigned char * hash)
|
||||
{
|
||||
if (ht == htMD5) MD5_Final(hash, &ctx.md5);
|
||||
else if (ht == htSHA1) SHA1_Final(hash, &ctx.sha1);
|
||||
else if (ht == htSHA256) SHA256_Final(hash, &ctx.sha256);
|
||||
else if (ht == htSHA512) SHA512_Final(hash, &ctx.sha512);
|
||||
memcpy (hash, gcry_md_read (ctx.md_handle, ht),
|
||||
gcry_md_get_algo_dlen (ht));
|
||||
gcry_md_close (ctx.md_handle);
|
||||
ctx.md_handle = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue