/*
* OPENSSL crypto backend implementation
*
- * Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
- * Copyright (C) 2010-2020 Milan Broz
+ * Copyright (C) 2010-2021 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2010-2021 Milan Broz
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
} u;
};
+struct hash_alg {
+ const char *name;
+ const char *openssl_name;
+};
+
/*
* Compatible wrappers for OpenSSL < 1.1.0 and LibreSSL < 2.7.0
*/
return openssl_backend_version();
}
+static const char *crypt_hash_compat_name(const char *name)
+{
+ const char *hash_name = name;
+ int i;
+ static struct hash_alg hash_algs[] = {
+ { "blake2b-512", "blake2b512" },
+ { "blake2s-256", "blake2s256" },
+ { NULL, NULL, }};
+
+ if (!name)
+ return NULL;
+
+ i = 0;
+ while (hash_algs[i].name) {
+ if (!strcasecmp(name, hash_algs[i].name)) {
+ hash_name = hash_algs[i].openssl_name;
+ break;
+ }
+ i++;
+ }
+
+ return hash_name;
+}
+
/* HASH */
int crypt_hash_size(const char *name)
{
- const EVP_MD *hash_id = EVP_get_digestbyname(name);
+ const EVP_MD *hash_id;
+ hash_id = EVP_get_digestbyname(crypt_hash_compat_name(name));
if (!hash_id)
return -EINVAL;
return -ENOMEM;
}
- h->hash_id = EVP_get_digestbyname(name);
+ h->hash_id = EVP_get_digestbyname(crypt_hash_compat_name(name));
if (!h->hash_id) {
EVP_MD_CTX_free(h->md);
free(h);
return -ENOMEM;
}
- h->hash_id = EVP_get_digestbyname(name);
+ h->hash_id = EVP_get_digestbyname(crypt_hash_compat_name(name));
if (!h->hash_id) {
HMAC_CTX_free(h->md);
free(h);
return -EINVAL;
if (!strcmp(kdf, "pbkdf2")) {
- hash_id = EVP_get_digestbyname(hash);
+ hash_id = EVP_get_digestbyname(crypt_hash_compat_name(hash));
if (!hash_id)
return -EINVAL;
key_bits /= 2;
r = snprintf(cipher_name, sizeof(cipher_name), "%s-%d-%s", name, key_bits, mode);
- if (r < 0 || r >= (int)sizeof(cipher_name))
+ if (r < 0 || (size_t)r >= sizeof(cipher_name))
return -EINVAL;
type = EVP_get_cipherbyname(cipher_name);