|
@@ -1,49 +1,44 @@ |
|
|
/** |
|
|
|
|
|
* @file decaf/crypto_255.h |
|
|
|
|
|
* @copyright |
|
|
|
|
|
* Copyright (c) 2015 Cryptography Research, Inc. \n |
|
|
|
|
|
* Released under the MIT License. See LICENSE.txt for license information. |
|
|
|
|
|
* @author Mike Hamburg |
|
|
|
|
|
* @brief Example Decaf cyrpto routines. |
|
|
|
|
|
* @warning These are merely examples, though they ought to be secure. But real |
|
|
|
|
|
* protocols will decide differently on magic numbers, formats, which items to |
|
|
|
|
|
* hash, etc. |
|
|
|
|
|
* @warning Experimental! The names, parameter orders etc are likely to change. |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#ifndef __DECAF_CRYPTO_255_H__ |
|
|
|
|
|
#define __DECAF_CRYPTO_255_H__ 1 |
|
|
|
|
|
|
|
|
|
|
|
#include <decaf/decaf_255.h> |
|
|
|
|
|
|
|
|
from gen_file import gen_file |
|
|
|
|
|
|
|
|
|
|
|
crypto_h = gen_file( |
|
|
|
|
|
name = "decaf/crypto_%(shortname)s.h", |
|
|
|
|
|
doc = """ |
|
|
|
|
|
@brief Example Decaf cyrpto routines. |
|
|
|
|
|
@warning These are merely examples, though they ought to be secure. But real |
|
|
|
|
|
protocols will decide differently on magic numbers, formats, which items to |
|
|
|
|
|
hash, etc. |
|
|
|
|
|
@warning Experimental! The names, parameter orders etc are likely to change. |
|
|
|
|
|
""", code = """ |
|
|
|
|
|
#include <decaf/%(c_ns)s.h> |
|
|
#include <decaf/shake.h> |
|
|
#include <decaf/shake.h> |
|
|
|
|
|
|
|
|
/** Number of bytes for a symmetric key (expanded to full key) */ |
|
|
/** Number of bytes for a symmetric key (expanded to full key) */ |
|
|
#define DECAF_255_SYMMETRIC_KEY_BYTES 32 |
|
|
|
|
|
|
|
|
#define %(C_NS)s_SYMMETRIC_KEY_BYTES 32 |
|
|
|
|
|
|
|
|
/** A symmetric key, the compressed point of a private key. */ |
|
|
/** A symmetric key, the compressed point of a private key. */ |
|
|
typedef unsigned char decaf_255_symmetric_key_t[DECAF_255_SYMMETRIC_KEY_BYTES]; |
|
|
|
|
|
|
|
|
typedef unsigned char %(c_ns)s_symmetric_key_t[%(C_NS)s_SYMMETRIC_KEY_BYTES]; |
|
|
|
|
|
|
|
|
/** An encoded public key. */ |
|
|
/** An encoded public key. */ |
|
|
typedef unsigned char decaf_255_public_key_t[DECAF_255_SER_BYTES]; |
|
|
|
|
|
|
|
|
typedef unsigned char %(c_ns)s_public_key_t[%(C_NS)s_SER_BYTES]; |
|
|
|
|
|
|
|
|
/** A signature. */ |
|
|
/** A signature. */ |
|
|
typedef unsigned char decaf_255_signature_t[DECAF_255_SER_BYTES + DECAF_255_SCALAR_BYTES]; |
|
|
|
|
|
|
|
|
typedef unsigned char %(c_ns)s_signature_t[%(C_NS)s_SER_BYTES + %(C_NS)s_SCALAR_BYTES]; |
|
|
|
|
|
|
|
|
typedef struct { |
|
|
typedef struct { |
|
|
/** @cond intetrnal */ |
|
|
/** @cond intetrnal */ |
|
|
/** The symmetric key from which everything is expanded */ |
|
|
/** The symmetric key from which everything is expanded */ |
|
|
decaf_255_symmetric_key_t sym; |
|
|
|
|
|
|
|
|
%(c_ns)s_symmetric_key_t sym; |
|
|
|
|
|
|
|
|
/** The scalar x */ |
|
|
/** The scalar x */ |
|
|
decaf_255_scalar_t secret_scalar; |
|
|
|
|
|
|
|
|
%(c_ns)s_scalar_t secret_scalar; |
|
|
|
|
|
|
|
|
/** x*Base */ |
|
|
/** x*Base */ |
|
|
decaf_255_public_key_t pub; |
|
|
|
|
|
|
|
|
%(c_ns)s_public_key_t pub; |
|
|
/** @endcond */ |
|
|
/** @endcond */ |
|
|
} /** Private key structure for pointers. */ |
|
|
} /** Private key structure for pointers. */ |
|
|
decaf_255_private_key_s, |
|
|
|
|
|
|
|
|
%(c_ns)s_private_key_s, |
|
|
/** A private key (gmp array[1] style). */ |
|
|
/** A private key (gmp array[1] style). */ |
|
|
decaf_255_private_key_t[1]; |
|
|
|
|
|
|
|
|
%(c_ns)s_private_key_t[1]; |
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
#ifdef __cplusplus |
|
|
extern "C" { |
|
|
extern "C" { |
|
@@ -54,16 +49,16 @@ extern "C" { |
|
|
* @param [out] priv The derived private key. |
|
|
* @param [out] priv The derived private key. |
|
|
* @param [in] proto The compressed or proto-key, which must be 32 random bytes. |
|
|
* @param [in] proto The compressed or proto-key, which must be 32 random bytes. |
|
|
*/ |
|
|
*/ |
|
|
void decaf_255_derive_private_key ( |
|
|
|
|
|
decaf_255_private_key_t priv, |
|
|
|
|
|
const decaf_255_symmetric_key_t proto |
|
|
|
|
|
|
|
|
void %(c_ns)s_derive_private_key ( |
|
|
|
|
|
%(c_ns)s_private_key_t priv, |
|
|
|
|
|
const %(c_ns)s_symmetric_key_t proto |
|
|
) NONNULL2 API_VIS; |
|
|
) NONNULL2 API_VIS; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @brief Destroy a private key. |
|
|
* @brief Destroy a private key. |
|
|
*/ |
|
|
*/ |
|
|
void decaf_255_destroy_private_key ( |
|
|
|
|
|
decaf_255_private_key_t priv |
|
|
|
|
|
|
|
|
void %(c_ns)s_destroy_private_key ( |
|
|
|
|
|
%(c_ns)s_private_key_t priv |
|
|
) NONNULL1 API_VIS; |
|
|
) NONNULL1 API_VIS; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -71,9 +66,9 @@ void decaf_255_destroy_private_key ( |
|
|
* @param [out] pub The extracted private key. |
|
|
* @param [out] pub The extracted private key. |
|
|
* @param [in] priv The private key. |
|
|
* @param [in] priv The private key. |
|
|
*/ |
|
|
*/ |
|
|
void decaf_255_private_to_public ( |
|
|
|
|
|
decaf_255_public_key_t pub, |
|
|
|
|
|
const decaf_255_private_key_t priv |
|
|
|
|
|
|
|
|
void %(c_ns)s_private_to_public ( |
|
|
|
|
|
%(c_ns)s_public_key_t pub, |
|
|
|
|
|
const %(c_ns)s_private_key_t priv |
|
|
) NONNULL2 API_VIS; |
|
|
) NONNULL2 API_VIS; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -92,11 +87,11 @@ void decaf_255_private_to_public ( |
|
|
* @retval DECAF_FAILURE Key exchange failed. |
|
|
* @retval DECAF_FAILURE Key exchange failed. |
|
|
*/ |
|
|
*/ |
|
|
decaf_error_t |
|
|
decaf_error_t |
|
|
decaf_255_shared_secret ( |
|
|
|
|
|
|
|
|
%(c_ns)s_shared_secret ( |
|
|
uint8_t *shared, |
|
|
uint8_t *shared, |
|
|
size_t shared_bytes, |
|
|
size_t shared_bytes, |
|
|
const decaf_255_private_key_t my_privkey, |
|
|
|
|
|
const decaf_255_public_key_t your_pubkey, |
|
|
|
|
|
|
|
|
const %(c_ns)s_private_key_t my_privkey, |
|
|
|
|
|
const %(c_ns)s_public_key_t your_pubkey, |
|
|
int me_first |
|
|
int me_first |
|
|
) NONNULL134 WARN_UNUSED API_VIS; |
|
|
) NONNULL134 WARN_UNUSED API_VIS; |
|
|
|
|
|
|
|
@@ -108,10 +103,10 @@ decaf_255_shared_secret ( |
|
|
* @param [in] strobe A STROBE context with the message. |
|
|
* @param [in] strobe A STROBE context with the message. |
|
|
*/ |
|
|
*/ |
|
|
void |
|
|
void |
|
|
decaf_255_sign_strobe ( |
|
|
|
|
|
|
|
|
%(c_ns)s_sign_strobe ( |
|
|
keccak_strobe_t strobe, |
|
|
keccak_strobe_t strobe, |
|
|
decaf_255_signature_t sig, |
|
|
|
|
|
const decaf_255_private_key_t priv |
|
|
|
|
|
|
|
|
%(c_ns)s_signature_t sig, |
|
|
|
|
|
const %(c_ns)s_private_key_t priv |
|
|
) NONNULL3 API_VIS; |
|
|
) NONNULL3 API_VIS; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -123,9 +118,9 @@ decaf_255_sign_strobe ( |
|
|
* @param [in] message_len The message's length. |
|
|
* @param [in] message_len The message's length. |
|
|
*/ |
|
|
*/ |
|
|
void |
|
|
void |
|
|
decaf_255_sign ( |
|
|
|
|
|
decaf_255_signature_t sig, |
|
|
|
|
|
const decaf_255_private_key_t priv, |
|
|
|
|
|
|
|
|
%(c_ns)s_sign ( |
|
|
|
|
|
%(c_ns)s_signature_t sig, |
|
|
|
|
|
const %(c_ns)s_private_key_t priv, |
|
|
const unsigned char *message, |
|
|
const unsigned char *message, |
|
|
size_t message_len |
|
|
size_t message_len |
|
|
) NONNULL3 API_VIS; |
|
|
) NONNULL3 API_VIS; |
|
@@ -141,10 +136,10 @@ decaf_255_sign ( |
|
|
* @return DECAF_FAILURE The signature did not verify successfully. |
|
|
* @return DECAF_FAILURE The signature did not verify successfully. |
|
|
*/ |
|
|
*/ |
|
|
decaf_error_t |
|
|
decaf_error_t |
|
|
decaf_255_verify_strobe ( |
|
|
|
|
|
|
|
|
%(c_ns)s_verify_strobe ( |
|
|
keccak_strobe_t strobe, |
|
|
keccak_strobe_t strobe, |
|
|
const decaf_255_signature_t sig, |
|
|
|
|
|
const decaf_255_public_key_t pub |
|
|
|
|
|
|
|
|
const %(c_ns)s_signature_t sig, |
|
|
|
|
|
const %(c_ns)s_public_key_t pub |
|
|
) NONNULL3 API_VIS WARN_UNUSED; |
|
|
) NONNULL3 API_VIS WARN_UNUSED; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -159,9 +154,9 @@ decaf_255_verify_strobe ( |
|
|
* @return DECAF_FAILURE The signature did not verify successfully. |
|
|
* @return DECAF_FAILURE The signature did not verify successfully. |
|
|
*/ |
|
|
*/ |
|
|
decaf_error_t |
|
|
decaf_error_t |
|
|
decaf_255_verify ( |
|
|
|
|
|
const decaf_255_signature_t sig, |
|
|
|
|
|
const decaf_255_public_key_t pub, |
|
|
|
|
|
|
|
|
%(c_ns)s_verify ( |
|
|
|
|
|
const %(c_ns)s_signature_t sig, |
|
|
|
|
|
const %(c_ns)s_public_key_t pub, |
|
|
const unsigned char *message, |
|
|
const unsigned char *message, |
|
|
size_t message_len |
|
|
size_t message_len |
|
|
) NONNULL3 API_VIS WARN_UNUSED; |
|
|
) NONNULL3 API_VIS WARN_UNUSED; |
|
@@ -169,7 +164,4 @@ decaf_255_verify ( |
|
|
#ifdef __cplusplus |
|
|
#ifdef __cplusplus |
|
|
} /* extern "C" */ |
|
|
} /* extern "C" */ |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#endif /* __DECAF_CRYPTO_255_H__ */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""") |