mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-27 20:27:12 +09:00
+ secretbox_xchacha20poly1305
This commit is contained in:
@@ -175,6 +175,8 @@ libsodium_la_SOURCES += \
|
||||
crypto_core/salsa2012/core_salsa2012_api.c \
|
||||
crypto_core/salsa208/ref/core_salsa208.c \
|
||||
crypto_core/salsa208/core_salsa208_api.c \
|
||||
crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305_api.c \
|
||||
crypto_secretbox/xchacha20poly1305/sodium/box_xchacha20poly1305.c \
|
||||
crypto_sign/ed25519/ref10/obsolete.c \
|
||||
crypto_stream/aes128ctr/portable/afternm_aes128ctr.c \
|
||||
crypto_stream/aes128ctr/stream_aes128ctr_api.c \
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "crypto_secretbox_xchacha20poly1305.h"
|
||||
|
||||
size_t
|
||||
crypto_secretbox_xchacha20poly1305_keybytes(void)
|
||||
{
|
||||
return crypto_secretbox_xchacha20poly1305_KEYBYTES;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_secretbox_xchacha20poly1305_noncebytes(void)
|
||||
{
|
||||
return crypto_secretbox_xchacha20poly1305_NONCEBYTES;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_secretbox_xchacha20poly1305_zerobytes(void)
|
||||
{
|
||||
return crypto_secretbox_xchacha20poly1305_ZEROBYTES;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_secretbox_xchacha20poly1305_boxzerobytes(void)
|
||||
{
|
||||
return crypto_secretbox_xchacha20poly1305_BOXZEROBYTES;
|
||||
}
|
||||
|
||||
size_t
|
||||
crypto_secretbox_xchacha20poly1305_macbytes(void)
|
||||
{
|
||||
return crypto_secretbox_xchacha20poly1305_MACBYTES;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "crypto_onetimeauth_poly1305.h"
|
||||
#include "crypto_secretbox_xchacha20poly1305.h"
|
||||
#include "crypto_stream_xchacha20.h"
|
||||
|
||||
int
|
||||
crypto_secretbox_xchacha20poly1305(unsigned char *c, const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (mlen < 32) {
|
||||
return -1;
|
||||
}
|
||||
crypto_stream_xchacha20_xor(c, m, mlen, n, k);
|
||||
crypto_onetimeauth_poly1305(c + 16, c + 32, mlen - 32, c);
|
||||
for (i = 0; i < 16; ++i) {
|
||||
c[i] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
crypto_secretbox_xchacha20poly1305_open(unsigned char *m, const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k)
|
||||
{
|
||||
unsigned char subkey[32];
|
||||
int i;
|
||||
|
||||
if (clen < 32) {
|
||||
return -1;
|
||||
}
|
||||
crypto_stream_xchacha20(subkey, 32, n, k);
|
||||
if (crypto_onetimeauth_poly1305_verify(c + 16, c + 32,
|
||||
clen - 32, subkey) != 0) {
|
||||
return -1;
|
||||
}
|
||||
crypto_stream_xchacha20_xor(m, c, clen, n, k);
|
||||
for (i = 0; i < 32; ++i) {
|
||||
m[i] = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -28,6 +28,7 @@ SODIUM_EXPORT = \
|
||||
sodium/crypto_scalarmult.h \
|
||||
sodium/crypto_scalarmult_curve25519.h \
|
||||
sodium/crypto_secretbox.h \
|
||||
sodium/crypto_secretbox_xchacha20poly1305.h \
|
||||
sodium/crypto_secretbox_xsalsa20poly1305.h \
|
||||
sodium/crypto_shorthash.h \
|
||||
sodium/crypto_shorthash_siphash24.h \
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "sodium/crypto_scalarmult_curve25519.h"
|
||||
#include "sodium/crypto_secretbox.h"
|
||||
#include "sodium/crypto_secretbox_xsalsa20poly1305.h"
|
||||
#include "sodium/crypto_secretbox_xchacha20poly1305.h"
|
||||
#include "sodium/crypto_shorthash.h"
|
||||
#include "sodium/crypto_shorthash_siphash24.h"
|
||||
#include "sodium/crypto_sign.h"
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef crypto_secretbox_xchacha20poly1305_H
|
||||
#define crypto_secretbox_xchacha20poly1305_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wlong-long"
|
||||
# endif
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define crypto_secretbox_xchacha20poly1305_KEYBYTES 32U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xchacha20poly1305_keybytes(void);
|
||||
|
||||
#define crypto_secretbox_xchacha20poly1305_NONCEBYTES 24U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xchacha20poly1305_noncebytes(void);
|
||||
|
||||
#define crypto_secretbox_xchacha20poly1305_MACBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xchacha20poly1305_macbytes(void);
|
||||
|
||||
#define crypto_secretbox_xchacha20poly1305_BOXZEROBYTES 16U
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xchacha20poly1305_boxzerobytes(void);
|
||||
|
||||
#define crypto_secretbox_xchacha20poly1305_ZEROBYTES \
|
||||
(crypto_secretbox_xchacha20poly1305_BOXZEROBYTES + \
|
||||
crypto_secretbox_xchacha20poly1305_MACBYTES)
|
||||
SODIUM_EXPORT
|
||||
size_t crypto_secretbox_xchacha20poly1305_zerobytes(void);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_xchacha20poly1305(unsigned char *c,
|
||||
const unsigned char *m,
|
||||
unsigned long long mlen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int crypto_secretbox_xchacha20poly1305_open(unsigned char *m,
|
||||
const unsigned char *c,
|
||||
unsigned long long clen,
|
||||
const unsigned char *n,
|
||||
const unsigned char *k);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user