Expose only crypto_aead_aes256gcm_*() not crypto_aead_aes256gcm_aesni_*()
libsodium typically doesn't expose specific implementations. It shouldn't be the case for that construction either, especially since an ARM8 implementation might be added later. We want a single interface for both.
This commit is contained in:
parent
dadc5d9906
commit
aa965a580b
@ -7,7 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "crypto_aead_aes256gcm_aesni.h"
|
||||
#include "crypto_aead_aes256gcm.h"
|
||||
#include "export.h"
|
||||
#include "runtime.h"
|
||||
#include "utils.h"
|
||||
@ -480,7 +480,7 @@ do { \
|
||||
} while(0)
|
||||
|
||||
int
|
||||
crypto_aead_aes256gcm_aesni_beforenm(crypto_aead_aes256gcm_state *ctx_,
|
||||
crypto_aead_aes256gcm_beforenm(crypto_aead_aes256gcm_state *ctx_,
|
||||
const unsigned char *k)
|
||||
{
|
||||
context *ctx = (context *) ctx_;
|
||||
@ -496,7 +496,7 @@ crypto_aead_aes256gcm_aesni_beforenm(crypto_aead_aes256gcm_state *ctx_,
|
||||
}
|
||||
|
||||
int
|
||||
crypto_aead_aes256gcm_aesni_encrypt_afternm(unsigned char *c, unsigned long long *clen,
|
||||
crypto_aead_aes256gcm_encrypt_afternm(unsigned char *c, unsigned long long *clen,
|
||||
const unsigned char *m, unsigned long long mlen,
|
||||
const unsigned char *ad, unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
@ -612,7 +612,7 @@ crypto_aead_aes256gcm_aesni_encrypt_afternm(unsigned char *c, unsigned long long
|
||||
}
|
||||
|
||||
int
|
||||
crypto_aead_aes256gcm_aesni_decrypt_afternm(unsigned char *m, unsigned long long *mlen_p,
|
||||
crypto_aead_aes256gcm_decrypt_afternm(unsigned char *m, unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c, unsigned long long clen,
|
||||
const unsigned char *ad, unsigned long long adlen,
|
||||
@ -761,7 +761,7 @@ crypto_aead_aes256gcm_aesni_decrypt_afternm(unsigned char *m, unsigned long long
|
||||
}
|
||||
|
||||
int
|
||||
crypto_aead_aes256gcm_aesni_encrypt(unsigned char *c,
|
||||
crypto_aead_aes256gcm_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
@ -773,14 +773,14 @@ crypto_aead_aes256gcm_aesni_encrypt(unsigned char *c,
|
||||
{
|
||||
crypto_aead_aes256gcm_state ctx;
|
||||
|
||||
crypto_aead_aes256gcm_aesni_beforenm(&ctx, k);
|
||||
crypto_aead_aes256gcm_beforenm(&ctx, k);
|
||||
|
||||
return crypto_aead_aes256gcm_aesni_encrypt_afternm
|
||||
return crypto_aead_aes256gcm_encrypt_afternm
|
||||
(c, clen_p, m, mlen, ad, adlen, nsec, npub, &ctx);
|
||||
}
|
||||
|
||||
int
|
||||
crypto_aead_aes256gcm_aesni_decrypt(unsigned char *m,
|
||||
crypto_aead_aes256gcm_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
@ -792,15 +792,14 @@ crypto_aead_aes256gcm_aesni_decrypt(unsigned char *m,
|
||||
{
|
||||
crypto_aead_aes256gcm_state ctx;
|
||||
|
||||
crypto_aead_aes256gcm_aesni_beforenm((crypto_aead_aes256gcm_state *)
|
||||
&ctx, k);
|
||||
crypto_aead_aes256gcm_beforenm(&ctx, k);
|
||||
|
||||
return crypto_aead_aes256gcm_aesni_decrypt_afternm
|
||||
return crypto_aead_aes256gcm_decrypt_afternm
|
||||
(m, mlen_p, nsec, c, clen, ad, adlen, npub, &ctx);
|
||||
}
|
||||
|
||||
int
|
||||
crypto_aead_aes256gcm_aesni_is_available(void)
|
||||
crypto_aead_aes256gcm_is_available(void)
|
||||
{
|
||||
return sodium_runtime_has_pclmul() & sodium_runtime_has_aesni();
|
||||
}
|
||||
@ -838,7 +837,7 @@ crypto_aead_aes256gcm_statebytes(void)
|
||||
#else
|
||||
|
||||
int
|
||||
crypto_aead_aes256gcm_aesni_is_available(void)
|
||||
crypto_aead_aes256gcm_is_available(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
SODIUM_EXPORT = \
|
||||
sodium.h \
|
||||
sodium/core.h \
|
||||
sodium/crypto_aead_aes256gcm_aesni.h \
|
||||
sodium/crypto_aead_aes256gcm.h \
|
||||
sodium/crypto_aead_chacha20poly1305.h \
|
||||
sodium/crypto_auth.h \
|
||||
sodium/crypto_auth_hmacsha256.h \
|
||||
|
@ -3,7 +3,7 @@
|
||||
#define sodium_H
|
||||
|
||||
#include "sodium/core.h"
|
||||
#include "sodium/crypto_aead_aes256gcm_aesni.h"
|
||||
#include "sodium/crypto_aead_aes256gcm.h"
|
||||
#include "sodium/crypto_aead_chacha20poly1305.h"
|
||||
#include "sodium/crypto_auth.h"
|
||||
#include "sodium/crypto_auth_hmacsha256.h"
|
||||
|
88
src/libsodium/include/sodium/crypto_aead_aes256gcm.h
Normal file
88
src/libsodium/include/sodium/crypto_aead_aes256gcm.h
Normal file
@ -0,0 +1,88 @@
|
||||
#ifndef crypto_aead_aes256gcm_H
|
||||
#define crypto_aead_aes256gcm_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# if __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_is_available(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_keybytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_NSECBYTES 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_nsecbytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_NPUBBYTES 12U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_pubbytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_ABYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_abytes(void);
|
||||
|
||||
typedef CRYPTO_ALIGN(16) unsigned char crypto_aead_aes256gcm_state[512];
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_beforenm(crypto_aead_aes256gcm_state *ctx_,
|
||||
const unsigned char *k);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_encrypt_afternm(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_decrypt_afternm(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,88 +0,0 @@
|
||||
#ifndef crypto_aead_aes256gcm_aesni_H
|
||||
#define crypto_aead_aes256gcm_aesni_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# if __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_aesni_is_available(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_keybytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_NSECBYTES 0U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_nsecbytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_NPUBBYTES 12U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_pubbytes(void);
|
||||
|
||||
#define crypto_aead_aes256gcm_ABYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_abytes(void);
|
||||
|
||||
typedef CRYPTO_ALIGN(16) unsigned char crypto_aead_aes256gcm_state[512];
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_aead_aes256gcm_statebytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_aesni_encrypt(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_aesni_decrypt(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const unsigned char *k);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_aesni_beforenm(crypto_aead_aes256gcm_state *ctx_,
|
||||
const unsigned char *k);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_aesni_encrypt_afternm(unsigned char *c,
|
||||
unsigned long long *clen_p,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *nsec,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_aead_aes256gcm_aesni_decrypt_afternm(unsigned char *m,
|
||||
unsigned long long *mlen_p,
|
||||
unsigned char *nsec,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *ad,
|
||||
unsigned long long adlen,
|
||||
const unsigned char *npub,
|
||||
const crypto_aead_aes256gcm_state *ctx_);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -3059,19 +3059,17 @@ tv(void)
|
||||
NULL, NULL, NULL);
|
||||
ciphertext = sodium_malloc(ciphertext_len);
|
||||
|
||||
crypto_aead_aes256gcm_aesni_encrypt(ciphertext, &found_ciphertext_len,
|
||||
crypto_aead_aes256gcm_encrypt(ciphertext, &found_ciphertext_len,
|
||||
message, message_len,
|
||||
ad, ad_len,
|
||||
NULL, nonce, key);
|
||||
ad, ad_len, NULL, nonce, key);
|
||||
|
||||
assert((size_t) found_ciphertext_len == ciphertext_len);
|
||||
if (memcmp(ciphertext, expected_ciphertext, ciphertext_len) != 0) {
|
||||
printf("Encryption of test vector #%u failed\n", (unsigned int) i);
|
||||
}
|
||||
decrypted = sodium_malloc(message_len);
|
||||
if (crypto_aead_aes256gcm_aesni_decrypt(decrypted, &found_message_len,
|
||||
NULL,
|
||||
ciphertext, ciphertext_len,
|
||||
if (crypto_aead_aes256gcm_decrypt(decrypted, &found_message_len,
|
||||
NULL, ciphertext, ciphertext_len,
|
||||
ad, ad_len, nonce, key) != 0) {
|
||||
printf("Verification of test vector #%u failed\n", (unsigned int) i);
|
||||
}
|
||||
@ -3095,7 +3093,7 @@ tv(void)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
if (crypto_aead_aes256gcm_aesni_is_available()) {
|
||||
if (crypto_aead_aes256gcm_is_available()) {
|
||||
tv();
|
||||
}
|
||||
printf("OK\n");
|
||||
|
Loading…
Reference in New Issue
Block a user