Browse Source

actually generate some headers

master
Michael Hamburg 8 years ago
parent
commit
c1306c75dc
4 changed files with 47 additions and 229 deletions
  1. +45
    -53
      src/gen_headers/crypto_h.py
  2. +1
    -1
      src/gen_headers/gen_file.py
  3. +1
    -0
      src/gen_headers/main.py
  4. +0
    -175
      src/public_include/decaf/crypto_448.h

src/public_include/decaf/crypto_255.h → src/gen_headers/crypto_h.py View File

@@ -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>

/** 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. */
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. */
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. */
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 {
/** @cond intetrnal */
/** The symmetric key from which everything is expanded */
decaf_255_symmetric_key_t sym;
%(c_ns)s_symmetric_key_t sym;
/** The scalar x */
decaf_255_scalar_t secret_scalar;
%(c_ns)s_scalar_t secret_scalar;
/** x*Base */
decaf_255_public_key_t pub;
%(c_ns)s_public_key_t pub;
/** @endcond */
} /** Private key structure for pointers. */
decaf_255_private_key_s,
%(c_ns)s_private_key_s,
/** A private key (gmp array[1] style). */
decaf_255_private_key_t[1];
%(c_ns)s_private_key_t[1];

#ifdef __cplusplus
extern "C" {
@@ -54,16 +49,16 @@ extern "C" {
* @param [out] priv The derived private key.
* @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;

/**
* @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;

/**
@@ -71,9 +66,9 @@ void decaf_255_destroy_private_key (
* @param [out] pub The extracted 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;
/**
@@ -92,11 +87,11 @@ void decaf_255_private_to_public (
* @retval DECAF_FAILURE Key exchange failed.
*/
decaf_error_t
decaf_255_shared_secret (
%(c_ns)s_shared_secret (
uint8_t *shared,
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
) NONNULL134 WARN_UNUSED API_VIS;
@@ -108,10 +103,10 @@ decaf_255_shared_secret (
* @param [in] strobe A STROBE context with the message.
*/
void
decaf_255_sign_strobe (
%(c_ns)s_sign_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;

/**
@@ -123,9 +118,9 @@ decaf_255_sign_strobe (
* @param [in] message_len The message's length.
*/
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,
size_t message_len
) NONNULL3 API_VIS;
@@ -141,10 +136,10 @@ decaf_255_sign (
* @return DECAF_FAILURE The signature did not verify successfully.
*/
decaf_error_t
decaf_255_verify_strobe (
%(c_ns)s_verify_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;

/**
@@ -159,9 +154,9 @@ decaf_255_verify_strobe (
* @return DECAF_FAILURE The signature did not verify successfully.
*/
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,
size_t message_len
) NONNULL3 API_VIS WARN_UNUSED;
@@ -169,7 +164,4 @@ decaf_255_verify (
#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* __DECAF_CRYPTO_255_H__ */


""")

+ 1
- 1
src/gen_headers/gen_file.py View File

@@ -29,7 +29,7 @@ def gen_file(name,doc,code,author="Mike Hamburg"):
ns_name = name % data
_,_,name_base = ns_name.rpartition("/")
header_guard = "__" + name_base.replace(".","_").upper() + "__"
header_guard = "__DECAF_" + name_base.replace(".","_").upper() + "__"
ns_doc = dedent(doc).strip().rstrip()
ns_doc = redoc(ns_name, ns_doc % data, author)


+ 1
- 0
src/gen_headers/main.py View File

@@ -12,6 +12,7 @@ prefixes = { "h" : args.hpre, "hxx" : args.hpre, "c" : args.cpre }

from decaf_hxx import decaf_hxx
from decaf_h import decaf_h
from crypto_h import crypto_h

for name,code in gend_files.iteritems():
_,_,name_suffix = name.partition(".")


+ 0
- 175
src/public_include/decaf/crypto_448.h View File

@@ -1,175 +0,0 @@
/**
* @file decaf/crypto_448.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_448_H__
#define __DECAF_CRYPTO_448_H__ 1

#include <decaf/decaf_448.h>
#include <decaf/shake.h>

/** Number of bytes for a symmetric key (expanded to full key) */
#define DECAF_448_SYMMETRIC_KEY_BYTES 32

/** A symmetric key, the compressed point of a private key. */
typedef unsigned char decaf_448_symmetric_key_t[DECAF_448_SYMMETRIC_KEY_BYTES];

/** An encoded public key. */
typedef unsigned char decaf_448_public_key_t[DECAF_448_SER_BYTES];

/** A signature. */
typedef unsigned char decaf_448_signature_t[DECAF_448_SER_BYTES + DECAF_448_SCALAR_BYTES];

typedef struct {
/** @cond intetrnal */
/** The symmetric key from which everything is expanded */
decaf_448_symmetric_key_t sym;
/** The scalar x */
decaf_448_scalar_t secret_scalar;
/** x*Base */
decaf_448_public_key_t pub;
/** @endcond */
} /** Private key structure for pointers. */
decaf_448_private_key_s,
/** A private key (gmp array[1] style). */
decaf_448_private_key_t[1];

#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Derive a key from its compressed form.
* @param [out] priv The derived private key.
* @param [in] proto The compressed or proto-key, which must be 32 random bytes.
*/
void decaf_448_derive_private_key (
decaf_448_private_key_t priv,
const decaf_448_symmetric_key_t proto
) NONNULL2 API_VIS;

/**
* @brief Destroy a private key.
*/
void decaf_448_destroy_private_key (
decaf_448_private_key_t priv
) NONNULL1 API_VIS;

/**
* @brief Convert a private key to a public one.
* @param [out] pub The extracted private key.
* @param [in] priv The private key.
*/
void decaf_448_private_to_public (
decaf_448_public_key_t pub,
const decaf_448_private_key_t priv
) NONNULL2 API_VIS;
/**
* @brief Compute a Diffie-Hellman shared secret.
*
* This is an example routine; real protocols would use something
* protocol-specific.
*
* @param [out] shared A buffer to store the shared secret.
* @param [in] shared_bytes The size of the buffer.
* @param [in] my_privkey My private key.
* @param [in] your_pubkey Your public key.
* @param [in] me_first Direction flag to break symmetry.
*
* @retval DECAF_SUCCESS Key exchange was successful.
* @retval DECAF_FAILURE Key exchange failed.
*/
decaf_error_t
decaf_448_shared_secret (
uint8_t *shared,
size_t shared_bytes,
const decaf_448_private_key_t my_privkey,
const decaf_448_public_key_t your_pubkey,
int me_first
) NONNULL134 WARN_UNUSED API_VIS;
/**
* @brief Sign a message from a STROBE context.
*
* @param [out] sig The signature.
* @param [in] priv Your private key.
* @param [in] strobe A STROBE context with the message.
*/
void
decaf_448_sign_strobe (
keccak_strobe_t strobe,
decaf_448_signature_t sig,
const decaf_448_private_key_t priv
) NONNULL3 API_VIS;

/**
* @brief Sign a message.
*
* @param [out] sig The signature.
* @param [in] priv Your private key.
* @param [in] message The message.
* @param [in] message_len The message's length.
*/
void
decaf_448_sign (
decaf_448_signature_t sig,
const decaf_448_private_key_t priv,
const unsigned char *message,
size_t message_len
) NONNULL3 API_VIS;

/**
* @brief Verify a signed message from its STROBE context.
*
* @param [in] sig The signature.
* @param [in] pub The public key.
* @param [in] strobe A STROBE context with the message.
*
* @return DECAF_SUCCESS The signature verified successfully.
* @return DECAF_FAILURE The signature did not verify successfully.
*/
decaf_error_t
decaf_448_verify_strobe (
keccak_strobe_t strobe,
const decaf_448_signature_t sig,
const decaf_448_public_key_t pub
) NONNULL3 API_VIS WARN_UNUSED;

/**
* @brief Verify a signed message.
*
* @param [in] sig The signature.
* @param [in] pub The public key.
* @param [in] message The message.
* @param [in] message_len The message's length.
*
* @return DECAF_SUCCESS The signature verified successfully.
* @return DECAF_FAILURE The signature did not verify successfully.
*/
decaf_error_t
decaf_448_verify (
const decaf_448_signature_t sig,
const decaf_448_public_key_t pub,
const unsigned char *message,
size_t message_len
) NONNULL3 API_VIS WARN_UNUSED;

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* __DECAF_CRYPTO_448_H__ */



Loading…
Cancel
Save