/* Generated from "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod" by precompile.pike running Pike v8.0 release 1089
 *
 * Do NOT edit this file.
 */

#undef PRECOMPILE_API_VERSION
#define PRECOMPILE_API_VERSION 6

#undef PRECOMPILE_SUB_PIKEVARS
#define PRECOMPILE_SUB_PIKEVARS 1

#undef PRECOMPILE_DYNAMIC_TYPES
#define PRECOMPILE_DYNAMIC_TYPES 1



#undef cmod___CMOD__
#define cmod___CMOD__ 1
#line 1 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
#line 3003 "/Users/hww3/devel/pike/lib/modules/Tools.pmod/Standalone.pmod/precompile.pike"







#line 3010 "/Users/hww3/devel/pike/lib/modules/Tools.pmod/Standalone.pmod/precompile.pike"
#line 1 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
/* -*- c -*-
|| This file is part of Pike. For copyright information see COPYRIGHT.
|| Pike is distributed under GPL, LGPL and MPL. See the file COPYING
|| for more information.
*/

#include "global.h"
#include "interpret.h"
#include "svalue.h"
#include "array.h"
#include "operators.h"
#include "threads.h"

/* For this_object() */
#include "object.h"
#include "module_support.h"

#include "nettle_config.h"

#ifdef HAVE_LIBNETTLE



#ifndef PIKE_UNUSED_ATTRIBUTE
#define PIKE_UNUSED_ATTRIBUTE
#endif
#define CMOD_MAP_PROGRAM_IDS_DEFINED 1
static int ___cmod_map_program_ids(int id) PIKE_UNUSED_ATTRIBUTE;
#ifndef TYPEOF
/* Compat with older Pikes. */
#define TYPEOF(SVAL)	((SVAL).type)
#define SUBTYPEOF(SVAL)	((SVAL).subtype)
#define SET_SVAL_TYPE(SVAL, TYPE)	(TYPEOF(SVAL) = TYPE)
#define SET_SVAL_SUBTYPE(SVAL, TYPE)	(SUBTYPEOF(SVAL) = TYPE)
#define SET_SVAL(SVAL, TYPE, SUBTYPE, FIELD, EXPR) do {	\
    /* Set the type afterwards to avoid a clobbered	\
     * svalue in case EXPR throws. */			\
    (SVAL).u.FIELD = (EXPR);				\
    SET_SVAL_TYPE((SVAL), (TYPE));			\
    SET_SVAL_SUBTYPE((SVAL), (SUBTYPE));		\
  } while(0)
#endif /* !TYPEOF */
#ifndef PIKE_UNUSED
/* Compat with Pike 7.8 and earlier. */
/* NB: Not strictly correct; PIKE_UNUSED was added the
 *     day after set_program_id_to_id(), but good enough.
 */
#ifndef UNUSED
#define UNUSED(X)	X
#endif
#ifndef set_program_id_to_id
/* NB: Recent Pike 7.8 has a #define that conflicts with
 *     the following declaration.
 */
static void set_program_id_to_id(void*UNUSED(id)){}
#endif
#else /* */
PMOD_EXPORT void set_program_id_to_id( int (*to)(int) );
#endif /* !PIKE_UNUSED */


#ifndef DEFAULT_CMOD_STORAGE
#define CMOD_COND_USED
#define DEFAULT_CMOD_STORAGE static
#endif
#define module_strings_declared
static struct pike_string *module_strings[2] = {
  NULL,
  NULL,
};
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_name_fun_num_used 1
#else
#define f_Nettle_AEAD_name_fun_num_used 1
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_iv_size_fun_num_used 1
#else
#define f_Nettle_AEAD_iv_size_fun_num_used 1
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_key_size_fun_num_used 1
#else
#undef f_Nettle_AEAD_key_size_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define Nettle_AEAD_program_fun_num_used 1
#else
#undef Nettle_AEAD_program_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_digest_size_fun_num_used 1
#else
#define f_Nettle_AEAD_digest_size_fun_num_used 1
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_block_size_fun_num_used 1
#else
#define f_Nettle_AEAD_block_size_fun_num_used 1
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_set_encrypt_key_fun_num_used 1
#else
#define f_Nettle_AEAD_State_set_encrypt_key_fun_num_used 1
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_crypt_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_crypt_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_make_key_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_make_key_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define Nettle_AEAD_State_program_fun_num_used 1
#else
#undef Nettle_AEAD_State_program_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_name_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_name_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_set_iv_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_set_iv_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_iv_size_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_iv_size_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_block_size_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_block_size_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_key_size_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_key_size_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define Nettle_CHACHA_POLY1305_program_fun_num_used 1
#else
#undef Nettle_CHACHA_POLY1305_program_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_digest_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_digest_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_digest_size_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_digest_size_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_set_decrypt_key_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_set_decrypt_key_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_Nettle_AEAD_State_update_fun_num_used 1
#else
#undef f_Nettle_AEAD_State_update_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define Nettle_CHACHA_POLY1305_State_program_fun_num_used 1
#else
#undef Nettle_CHACHA_POLY1305_State_program_fun_num_used
#endif
#line 24 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
#include "nettle.h"

#ifdef HAVE_NETTLE_CHACHA_POLY1305_H
#include <nettle/chacha-poly1305.h>
#endif

#include <stdio.h>
#include <stdarg.h>

/*! @module Nettle
 */

/* Calls Pike_error on errors */
typedef void (*pike_nettle_set_key_func)(void *ctx,
ptrdiff_t length,
const uint8_t *key);

struct pike_aead
{
const char *name;

size_t context_size;

unsigned digest_size;

unsigned block_size;

/* Suggested key size; other sizes are sometimes possible. */
unsigned key_size;

unsigned iv_size;

pike_nettle_set_key_func set_encrypt_key;
pike_nettle_set_key_func set_decrypt_key;

/* NB: Use pike_nettle_hash_update_func here to get both a length field,
   *     and a const uint8_t source.
   */
pike_nettle_hash_update_func set_iv;

pike_nettle_crypt_func encrypt;
pike_nettle_crypt_func decrypt;

pike_nettle_hash_update_func update;
pike_nettle_hash_digest_func digest;
};

#define _PIKE_AEAD(name, NAME) {		\
  #name,					\
  sizeof(struct name##_ctx),			\
  NAME##_DIGEST_SIZE,				\
  NAME##_BLOCK_SIZE,				\
  NAME##_KEY_SIZE,				\
  NAME##_NONCE_SIZE,				\
  pike_##name##_set_encrypt_key,		\
  pike_##name##_set_decrypt_key,		\
  pike_##name##_set_iv,				\
  (pike_nettle_crypt_func) name##_encrypt,	\
  (pike_nettle_crypt_func) name##_decrypt,	\
  (pike_nettle_hash_update_func) name##_update, \
  (pike_nettle_hash_digest_func) name##_digest, \
}

/*! @class AEAD
 *!
 *! Represents information about an Authenticated Encryption with
 *! Associated Data (AEAD) algorithm, such as name, key size, digest size,
 *! and block size.
 */

#undef class_Nettle_AEAD_defined
#define class_Nettle_AEAD_defined
DEFAULT_CMOD_STORAGE struct program *Nettle_AEAD_program=NULL;

#ifdef Nettle_AEAD_program_fun_num_used
DEFAULT_CMOD_STORAGE int Nettle_AEAD_program_fun_num=-1;
#endif /* Nettle_AEAD_program_fun_num_used */
/*! @decl inherit __builtin.Nettle.AEAD
   */

#undef inherit_cq__22__builtin_2ENettle_2EAEAD_22_Nettle_AEAD_defined
#define inherit_cq__22__builtin_2ENettle_2EAEAD_22_Nettle_AEAD_defined
#line 97 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
static int Nettle_AEAD_cq__22__builtin_2ENettle_2EAEAD_22_inh_num = -1;
#line 97 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
static int Nettle_AEAD_cq__22__builtin_2ENettle_2EAEAD_22_inh_offset = -1;

#undef var_meta_Nettle_AEAD_defined
#define var_meta_Nettle_AEAD_defined

#undef THIS
#define THIS ((struct Nettle_AEAD_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef THIS_NETTLE_AEAD
#define THIS_NETTLE_AEAD ((struct Nettle_AEAD_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_NETTLE_AEAD
#define OBJ2_NETTLE_AEAD(o) ((struct Nettle_AEAD_struct *)(o->storage+Nettle_AEAD_storage_offset))

#undef GET_NETTLE_AEAD_STORAGE
#define GET_NETTLE_AEAD_STORAGE(o) ((struct Nettle_AEAD_struct *)(o->storage+Nettle_AEAD_storage_offset)
static ptrdiff_t Nettle_AEAD_storage_offset;
struct Nettle_AEAD_struct {

#ifdef var_meta_Nettle_AEAD_defined
#line 99 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
const struct pike_aead *meta;
#endif /* var_meta_Nettle_AEAD_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct Nettle_AEAD_struct *Nettle_AEAD_gdb_dummy_ptr;
#endif
/*! @decl string(0..255) name()
   *!
   *! @returns
   *!   A human readable name for the algorithm.
   */
#define f_Nettle_AEAD_name_defined

#ifdef f_Nettle_AEAD_name_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_name_fun_num = 0;

#endif /* f_Nettle_AEAD_name_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_name(INT32 args) {
#line 106 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("name",args,0);
#line 108 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
if (!THIS->meta)
Pike_error("Cipher not properly initialized.\n");

push_text(THIS->meta->name);
}

}
/*! @decl int(0..) digest_size(void)
   *!
   *! Returns the size of a MAC digest.
   */
#define f_Nettle_AEAD_digest_size_defined

#ifdef f_Nettle_AEAD_digest_size_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_digest_size_fun_num = 0;

#endif /* f_Nettle_AEAD_digest_size_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_digest_size(INT32 args) {
#line 119 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("digest_size",args,0);
#line 121 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
if (!THIS->meta)
Pike_error("Cipher not properly initialized.\n");

push_int(THIS->meta->digest_size);
}

}
/*! @decl int(0..) key_size()
   *!
   *! @returns
   *!   The recommended key size for the cipher.
   */
#define f_Nettle_AEAD_key_size_defined

#ifdef f_Nettle_AEAD_key_size_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_key_size_fun_num = 0;

#endif /* f_Nettle_AEAD_key_size_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_key_size(INT32 args) {
#line 133 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("key_size",args,0);
#line 135 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
if (!THIS->meta)
Pike_error("Cipher not properly initialized.\n");

push_int(THIS->meta->key_size);
}

}
/*! @decl int(0..) block_size()
   *!
   *! @returns
   *!   The block size of the AEAD algorithm.
   *!
   *! @note
   *!   Note that AEAD algorithms often support automatic padding,
   *!   so that the last block does not need to be complete.
   */
#define f_Nettle_AEAD_block_size_defined

#ifdef f_Nettle_AEAD_block_size_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_block_size_fun_num = 0;

#endif /* f_Nettle_AEAD_block_size_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_block_size(INT32 args) {
#line 151 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("block_size",args,0);
#line 153 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
if (!THIS->meta)
Pike_error("Cipher not properly initialized.\n");

push_int(THIS->meta->block_size);
}

}
/*! @decl int(0..) iv_size(void)
   *!
   *! Returns the size of the iv/nonce of the AEAD algorithm (if any).
   *!
   *! Returns @expr{0@} (zero) if there is no configurable iv/nonce.
   */
#define f_Nettle_AEAD_iv_size_defined

#ifdef f_Nettle_AEAD_iv_size_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_iv_size_fun_num = 0;

#endif /* f_Nettle_AEAD_iv_size_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_iv_size(INT32 args) {
#line 166 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("iv_size",args,0);
#line 168 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
if (!THIS->meta)
Pike_error("AEAD not properly initialized.\n");

push_int(THIS->meta->iv_size);
}

}

#undef internal_init_Nettle_AEAD_defined
#define internal_init_Nettle_AEAD_defined

#undef Nettle_AEAD_event_handler_defined
#define Nettle_AEAD_event_handler_defined
static void init_Nettle_AEAD_struct(void)
#line 176 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
THIS->meta = NULL;
}

/*! @class State
   *!
   *! Base class for AEAD contexts.
   */

#undef class_Nettle_AEAD_State_defined
#define class_Nettle_AEAD_State_defined
DEFAULT_CMOD_STORAGE struct program *Nettle_AEAD_State_program=NULL;

#ifdef Nettle_AEAD_State_program_fun_num_used
DEFAULT_CMOD_STORAGE int Nettle_AEAD_State_program_fun_num=-1;
#endif /* Nettle_AEAD_State_program_fun_num_used */
/*! @decl inherit AEAD::State
*/


#undef extra_Nettle_AEAD_State_defined
#define extra_Nettle_AEAD_State_defined

#undef var_crypt_Nettle_AEAD_State_defined
#define var_crypt_Nettle_AEAD_State_defined

#undef var_ctx_Nettle_AEAD_State_defined
#define var_ctx_Nettle_AEAD_State_defined

#undef var_key_size_Nettle_AEAD_State_defined
#define var_key_size_Nettle_AEAD_State_defined

#undef THIS
#define THIS ((struct Nettle_AEAD_State_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef THIS_NETTLE_AEAD_STATE
#define THIS_NETTLE_AEAD_STATE ((struct Nettle_AEAD_State_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_NETTLE_AEAD_STATE
#define OBJ2_NETTLE_AEAD_STATE(o) ((struct Nettle_AEAD_State_struct *)(o->storage+Nettle_AEAD_State_storage_offset))

#undef GET_NETTLE_AEAD_STATE_STORAGE
#define GET_NETTLE_AEAD_STATE_STORAGE(o) ((struct Nettle_AEAD_State_struct *)(o->storage+Nettle_AEAD_State_storage_offset)
static ptrdiff_t Nettle_AEAD_State_storage_offset;
struct Nettle_AEAD_State_struct {

#ifdef var_crypt_Nettle_AEAD_State_defined
#line 215 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
pike_nettle_crypt_func crypt;
#endif /* var_crypt_Nettle_AEAD_State_defined */

#ifdef var_ctx_Nettle_AEAD_State_defined
#line 216 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
void *ctx;
#endif /* var_ctx_Nettle_AEAD_State_defined */

#ifdef var_key_size_Nettle_AEAD_State_defined
#line 217 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
int key_size;
#endif /* var_key_size_Nettle_AEAD_State_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct Nettle_AEAD_State_struct *Nettle_AEAD_State_gdb_dummy_ptr;
#endif
#line 219 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
#define GET_META()	(((struct Nettle_AEAD_struct *)parent_storage(1, Nettle_AEAD_program))->meta)

/* Generate a random string of length @[size] on top of the stack. */
static void low_make_key(INT32 size)
{
push_text("Crypto.Random");
APPLY_MASTER("resolv",1);
if(TYPEOF(Pike_sp[-1]) != T_OBJECT)
Pike_error("Failed to resolv Crypto.Random.\n");
push_int(size);
apply(Pike_sp[-2].u.object, "random_string", 1);
stack_swap();
pop_stack();
}

/*! @decl State set_encrypt_key(string(0..255) key)
     *!
     *! Initializes the object for encryption. The @[key] memory will be
     *! cleared before released.
     *!
     *! @seealso
     *!   @[set_decrypt_key], @[crypt]
     */
#define f_Nettle_AEAD_State_set_encrypt_key_defined

#ifdef f_Nettle_AEAD_State_set_encrypt_key_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_set_encrypt_key_fun_num = 0;

#endif /* f_Nettle_AEAD_State_set_encrypt_key_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_set_encrypt_key(INT32 args) {
#line 242 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
struct pike_string * key;
#line 242 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 1) wrong_number_of_args_error("set_encrypt_key",args,1);
#line 242 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("set_encrypt_key",1,"string(0..255)");
#line 242 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
debug_malloc_pass(key=Pike_sp[0-1].u.string);
#line 245 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
const struct pike_aead *meta = GET_META();

if (!THIS->ctx || !meta)
Pike_error("CipherState not properly initialized.\n");

NO_WIDE_STRING(key);
key->flags |= STRING_CLEAR_ON_EXIT;
meta->set_encrypt_key(THIS->ctx, key->len, (const uint8_t*)key->str);

THIS->crypt = meta->encrypt;
THIS->key_size = key->len;

do { struct object * ret_=(this_object()); pop_stack(); push_object(ret_); return; }while(0);
#line 259 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
}

}
/*! @decl State set_decrypt_key(string(0..255) key)
     *!
     *! Initializes the object for decryption. The @[key] memory will be
     *! cleared before released.
     *!
     *! @seealso
     *!   @[set_encrypt_key], @[crypt]
     */
#define f_Nettle_AEAD_State_set_decrypt_key_defined

#ifdef f_Nettle_AEAD_State_set_decrypt_key_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_set_decrypt_key_fun_num = 0;

#endif /* f_Nettle_AEAD_State_set_decrypt_key_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_set_decrypt_key(INT32 args) {
#line 269 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
struct pike_string * key;
#line 269 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 1) wrong_number_of_args_error("set_decrypt_key",args,1);
#line 269 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("set_decrypt_key",1,"string(0..255)");
#line 269 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
debug_malloc_pass(key=Pike_sp[0-1].u.string);
#line 272 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
const struct pike_aead *meta = GET_META();

if (!THIS->ctx || !meta)
Pike_error("CipherState not properly initialized.\n");

NO_WIDE_STRING(key);
key->flags |= STRING_CLEAR_ON_EXIT;
meta->set_decrypt_key(THIS->ctx, key->len, (const uint8_t*)key->str);
THIS->crypt = meta->decrypt;
THIS->key_size = key->len;

do { struct object * ret_=(this_object()); pop_stack(); push_object(ret_); return; }while(0);
#line 285 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
}

}
/*! @decl string(0..255) make_key()
     *!
     *! Generate a key by calling @[Crypto.Random.random_string] and
     *! initialize this object for encryption with that key.
     *!
     *! @returns
     *!   The generated key. The key memory will be cleared before
     *!   released.
     *!
     *! @seealso
     *!   @[set_encrypt_key]
     */
#define f_Nettle_AEAD_State_make_key_defined

#ifdef f_Nettle_AEAD_State_make_key_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_make_key_fun_num = 0;

#endif /* f_Nettle_AEAD_State_make_key_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_make_key(INT32 args) {
#line 299 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("make_key",args,0);
#line 301 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
const struct pike_aead *meta = GET_META();

low_make_key(meta->key_size);

stack_dup();
Pike_sp[-1].u.string->flags |= STRING_CLEAR_ON_EXIT;
apply_current(f_Nettle_AEAD_State_set_encrypt_key_fun_num, 1);
pop_stack();
}

}
/*! @decl string(0..255) crypt(string(0..255) data)
     *!
     *! Encrypts or decrypts data, using the current key. Neither the
     *! input nor output data is automatically memory scrubbed,
     *! unless @[String.secure] has been called on them.
     *!
     *! @param data
     *!   Data must be an integral number of blocks, except for the
     *!   last segment.
     *!
     *! @returns
     *!   The encrypted or decrypted data.
     */
#define f_Nettle_AEAD_State_crypt_defined

#ifdef f_Nettle_AEAD_State_crypt_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_crypt_fun_num = 0;

#endif /* f_Nettle_AEAD_State_crypt_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_crypt(INT32 args) {
#line 325 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
struct pike_string * data;
#line 325 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 1) wrong_number_of_args_error("crypt",args,1);
#line 325 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("crypt",1,"string(0..255)");
#line 325 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
debug_malloc_pass(data=Pike_sp[0-1].u.string);
#line 327 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
const struct pike_aead *meta = GET_META();
struct pike_string *result;
pike_nettle_crypt_func crypt = THIS->crypt;
void *ctx = THIS->ctx;

if (!THIS->ctx || !THIS->crypt || !meta)
Pike_error("CipherState not properly initialized.\n");

NO_WIDE_STRING(data);

result = begin_shared_string(data->len);
if (data->len >= CIPHER_THREADS_ALLOW_THRESHOLD) {
THREADS_ALLOW();
crypt(ctx, data->len, STR0(result), STR0(data));
THREADS_DISALLOW();
} else {
crypt(ctx, data->len, STR0(result), STR0(data));
}
result = end_shared_string(result);
push_string(result);
}

}
/*! @decl string(0..255) name(void)
     *!
     *! @returns
     *!   A human readable name for the algorithm.
     *!
     *! @note
     *!   The default implementation just calls @[Cipher::name()]
     *!   in the parent.
     */
#define f_Nettle_AEAD_State_name_defined

#ifdef f_Nettle_AEAD_State_name_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_name_fun_num = 0;

#endif /* f_Nettle_AEAD_State_name_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_name(INT32 args) {
#line 359 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("name",args,0);
#line 361 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
apply_external(1, f_Nettle_AEAD_name_fun_num, args);
}

}
/*! @decl int(0..) digest_size(void)
     *!
     *! Returns the size of a MAC digest.
     */
#define f_Nettle_AEAD_State_digest_size_defined

#ifdef f_Nettle_AEAD_State_digest_size_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_digest_size_fun_num = 0;

#endif /* f_Nettle_AEAD_State_digest_size_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_digest_size(INT32 args) {
#line 369 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("digest_size",args,0);
#line 371 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
apply_external(1, f_Nettle_AEAD_digest_size_fun_num, args);
}

}
/*! @decl int(0..) key_size(void)
     *!
     *! @returns
     *!   The actual key size for this cipher.
     */
#define f_Nettle_AEAD_State_key_size_defined

#ifdef f_Nettle_AEAD_State_key_size_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_key_size_fun_num = 0;

#endif /* f_Nettle_AEAD_State_key_size_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_key_size(INT32 args) {
#line 380 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("key_size",args,0);
#line 382 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
do { INT_TYPE ret_=(THIS->key_size);  push_int(ret_); return; }while(0);
#line 384 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
}

}
/*! @decl int(0..) block_size(void)
     *!
     *! @returns
     *!   The block size for this cipher.
     *!
     *! @note
     *!   The default implementation just calls @[Cipher::block_size()]
     *!   in the parent.
     */
#define f_Nettle_AEAD_State_block_size_defined

#ifdef f_Nettle_AEAD_State_block_size_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_block_size_fun_num = 0;

#endif /* f_Nettle_AEAD_State_block_size_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_block_size(INT32 args) {
#line 395 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("block_size",args,0);
#line 397 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
apply_external(1, f_Nettle_AEAD_block_size_fun_num, args);
}

}
/*! @decl int(0..) iv_size(void)
     *!
     *! Returns the size of the iv/nonce of the AEAD algorithm (if any).
     *!
     *! Returns @expr{0@} (zero) if there is no configurable iv/nonce.
     */
#define f_Nettle_AEAD_State_iv_size_defined

#ifdef f_Nettle_AEAD_State_iv_size_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_iv_size_fun_num = 0;

#endif /* f_Nettle_AEAD_State_iv_size_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_iv_size(INT32 args) {
#line 407 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 0) wrong_number_of_args_error("iv_size",args,0);
#line 409 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
apply_external(1, f_Nettle_AEAD_iv_size_fun_num, args);
}

}
/*! @decl State set_iv(string(0..255) iv)
     *!
     *! Set the iv/nonce (if supported) for the AEAD.
     *!
     *! @returns
     *!   Returns @expr{this@} in order to simplify chaining
     *!   of function calls.
     */
#define f_Nettle_AEAD_State_set_iv_defined

#ifdef f_Nettle_AEAD_State_set_iv_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_set_iv_fun_num = 0;

#endif /* f_Nettle_AEAD_State_set_iv_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_set_iv(INT32 args) {
#line 421 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
struct pike_string * iv;
#line 421 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 1) wrong_number_of_args_error("set_iv",args,1);
#line 421 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("set_iv",1,"string(0..255)");
#line 421 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
debug_malloc_pass(iv=Pike_sp[0-1].u.string);
#line 424 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
void *ctx = THIS->ctx;
const struct pike_aead *meta = GET_META();

if (!ctx || !meta)
Pike_error("State not properly initialized.\n");

iv->flags |= STRING_CLEAR_ON_EXIT;
NO_WIDE_STRING(iv);

/* NB: Check iv length here so that we can use the
       *     Nettle implementation straight in meta->set_iv.
       */
if ((unsigned)iv->len != meta->iv_size || !meta->iv_size) {
Pike_error("Invalid iv/nonce.\n");
}

meta->set_iv(ctx, iv->len, STR0(iv));

push_object(this_object());
}

}
/*! @decl State update(string(0..255) data)
     *!
     *! Add some more associated data.
     *!
     *! All associated data typically needs to be added before
     *! any data to actually encrypt.
     *!
     *! @returns
     *!   Returns @expr{this@} in order to simplify chaining
     *!   of function calls.
     */
#define f_Nettle_AEAD_State_update_defined

#ifdef f_Nettle_AEAD_State_update_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_update_fun_num = 0;

#endif /* f_Nettle_AEAD_State_update_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_update(INT32 args) {
#line 457 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
struct pike_string * data;
#line 457 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args != 1) wrong_number_of_args_error("update",args,1);
#line 457 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("update",1,"string(0..255)");
#line 457 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
debug_malloc_pass(data=Pike_sp[0-1].u.string);
#line 460 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
void *ctx = THIS->ctx;
const struct pike_aead *meta = GET_META();

if (!ctx || !meta)
Pike_error("State not properly initialized.\n");

NO_WIDE_STRING(data);

/* Only thread this block for significant data size */
if (data->len > HASH_THREADS_ALLOW_THRESHOLD) {
THREADS_ALLOW();
meta->update(ctx, data->len, (const uint8_t *)data->str);
THREADS_DISALLOW();
} else {
meta->update(ctx, data->len, (const uint8_t *)data->str);
}

push_object(this_object());
}

}
/*! @decl string(0..255) digest(int|void length)
     *!
     *! Generates a digest, and resets the AEAD contents.
     *!
     *! Also updates the iv/nonce (if any).
     *!
     *! @param length
     *!   If the length argument is provided, the digest is truncated
     *!   to the given length.
     *!
     *! @returns
     *!   The digest.
     */
#define f_Nettle_AEAD_State_digest_defined

#ifdef f_Nettle_AEAD_State_digest_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_Nettle_AEAD_State_digest_fun_num = 0;

#endif /* f_Nettle_AEAD_State_digest_fun_num_used */
DEFAULT_CMOD_STORAGE void f_Nettle_AEAD_State_digest(INT32 args) {
#line 494 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
struct svalue * arg;
#line 494 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(args > 1) wrong_number_of_args_error("digest",args,1);
#line 494 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if ((args > 0) &&
    ((TYPEOF(Pike_sp[0-args]) != PIKE_T_INT) ||
     (SUBTYPEOF(Pike_sp[0-args]) != NUMBER_UNDEFINED))) {
#line 494 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("digest",1,"int|void");
#line 494 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
arg=Pike_sp+0-args; dmalloc_touch_svalue(Pike_sp+0-args);
#line 494 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
} else arg = NULL;
{
const struct pike_aead *meta;
struct pike_string *digest;
unsigned length;

meta = GET_META();

if (!THIS->ctx || !meta)
Pike_error("State not properly initialized.\n");

if (!arg)
length = meta->digest_size;
else
{
if (TYPEOF(*arg) != PIKE_T_INT)
Pike_error("Bad argument type.\n");
if (arg->u.integer < 0)
Pike_error("Invalid length, must be positive.\n");
if ((unsigned)arg->u.integer > meta->digest_size)
Pike_error("Unsupported digest length.\n");

length = arg->u.integer;
}

digest = begin_shared_string(length);
meta->digest(THIS->ctx, length, (uint8_t *)digest->str);
push_string(end_shared_string(digest));
}

}

#undef internal_init_Nettle_AEAD_State_defined
#define internal_init_Nettle_AEAD_State_defined

#undef Nettle_AEAD_State_event_handler_defined
#define Nettle_AEAD_State_event_handler_defined
static void init_Nettle_AEAD_State_struct(void)
#line 525 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
THIS->ctx = NULL;
THIS->crypt = NULL;
THIS->key_size = 0;
}


#undef Nettle_AEAD_State_gc_live_obj
#define Nettle_AEAD_State_gc_live_obj

#undef internal_exit_Nettle_AEAD_State_defined
#define internal_exit_Nettle_AEAD_State_defined

#undef Nettle_AEAD_State_event_handler_defined
#define Nettle_AEAD_State_event_handler_defined
static void exit_Nettle_AEAD_State_struct(void)
#line 532 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
if (THIS->ctx && Pike_fp->current_object->prog)
{
const struct pike_aead *meta = GET_META();
assert(meta);
memset(THIS->ctx, 0, meta->context_size);
}
}

#ifdef Nettle_AEAD_State_event_handler_defined
static void Nettle_AEAD_State_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_Nettle_AEAD_State_defined
  case PROG_EVENT_INIT: init_Nettle_AEAD_State_struct(); break;

#endif /* internal_init_Nettle_AEAD_State_defined */

#ifdef internal_exit_Nettle_AEAD_State_defined
  case PROG_EVENT_EXIT: exit_Nettle_AEAD_State_struct(); break;

#endif /* internal_exit_Nettle_AEAD_State_defined */
  default: break; 
  }
}

#endif /* Nettle_AEAD_State_event_handler_defined */
/*! @endclass State */

#ifdef Nettle_AEAD_event_handler_defined
static void Nettle_AEAD_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_Nettle_AEAD_defined
  case PROG_EVENT_INIT: init_Nettle_AEAD_struct(); break;

#endif /* internal_init_Nettle_AEAD_defined */
  default: break; 
  }
}

#endif /* Nettle_AEAD_event_handler_defined */
/*! @endclass AEAD
 */

#line 546 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
/* FIXME: Consider adding special cases for gcm-aes and gcm-camellia. */

#ifdef HAVE_NETTLE_CHACHA_POLY1305_H

/* NB: Nettle 3.0 had an implementation of the draft AEAD construct,
 *     which is incompatible with the RFC 7539 definition.
 *
 *     In the old implementation the length of the nonce was 8 bytes.
 */
#if CHACHA_POLY1305_NONCE_SIZE == 12

static void pike_chacha_poly1305_set_encrypt_key(void *ctx,
ptrdiff_t length,
const uint8_t *key)
{
if (length != CHACHA_POLY1305_KEY_SIZE) {
Pike_error("Bad key size.\n");
}
chacha_poly1305_set_key(ctx, key);
}

static void pike_chacha_poly1305_set_decrypt_key(void *ctx,
ptrdiff_t length,
const uint8_t *key)
{
if (length != CHACHA_POLY1305_KEY_SIZE) {
Pike_error("Bad key size.\n");
}
chacha_poly1305_set_key(ctx, key);
}

static void pike_chacha_poly1305_set_iv(void *ctx,
pike_nettle_size_t length,
const uint8_t *key)
{
if (length != CHACHA_POLY1305_NONCE_SIZE) {
Pike_error("Bad nonce size.\n");
}
chacha_poly1305_set_nonce(ctx, key);
}



#line 1 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
#line 1 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
/* -*- C -*-
 *
 * Cmod header-file acting as a template for the AEAD classes.
 */

/*! @class CHACHA_POLY1305
*!
*! Implementation of the CHACHA_POLY1305 AEAD algorithm.
*!
*/

#undef class_Nettle_CHACHA_POLY1305_defined
#define class_Nettle_CHACHA_POLY1305_defined
DEFAULT_CMOD_STORAGE struct program *Nettle_CHACHA_POLY1305_program=NULL;

#ifdef Nettle_CHACHA_POLY1305_program_fun_num_used
DEFAULT_CMOD_STORAGE int Nettle_CHACHA_POLY1305_program_fun_num=-1;
#endif /* Nettle_CHACHA_POLY1305_program_fun_num_used */
/*! @decl inherit AEAD
*/

#undef inherit_Nettle_AEAD_Nettle_CHACHA_POLY1305_defined
#define inherit_Nettle_AEAD_Nettle_CHACHA_POLY1305_defined
#line 15 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
static int Nettle_CHACHA_POLY1305_Nettle_AEAD_inh_num = -1;
#line 15 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
static int Nettle_CHACHA_POLY1305_Nettle_AEAD_inh_offset = -1;
#line 17 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
static const struct pike_aead pike_chacha_poly1305 =
_PIKE_AEAD(chacha_poly1305, CHACHA_POLY1305);


#undef internal_init_Nettle_CHACHA_POLY1305_defined
#define internal_init_Nettle_CHACHA_POLY1305_defined

#undef Nettle_CHACHA_POLY1305_event_handler_defined
#define Nettle_CHACHA_POLY1305_event_handler_defined
static void init_Nettle_CHACHA_POLY1305_struct(void)
#line 21 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
{
struct Nettle_AEAD_struct *aead;
ASSIGN_CURRENT_STORAGE(aead, struct Nettle_AEAD_struct, 1,
Nettle_AEAD_program);
aead->meta = &pike_chacha_poly1305;
}

/*! @class State
*!
*! State for CHACHA_POLY1305 encyption.
*!
*/

#undef class_Nettle_CHACHA_POLY1305_State_defined
#define class_Nettle_CHACHA_POLY1305_State_defined
DEFAULT_CMOD_STORAGE struct program *Nettle_CHACHA_POLY1305_State_program=NULL;

#ifdef Nettle_CHACHA_POLY1305_State_program_fun_num_used
DEFAULT_CMOD_STORAGE int Nettle_CHACHA_POLY1305_State_program_fun_num=-1;
#endif /* Nettle_CHACHA_POLY1305_State_program_fun_num_used */
/*! @decl inherit AEAD::State
*/


#undef extra_Nettle_CHACHA_POLY1305_State_defined
#define extra_Nettle_CHACHA_POLY1305_State_defined

#undef var_chacha_poly1305_Nettle_CHACHA_POLY1305_State_defined
#define var_chacha_poly1305_Nettle_CHACHA_POLY1305_State_defined

#undef THIS
#define THIS ((struct Nettle_CHACHA_POLY1305_State_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef THIS_NETTLE_CHACHA_POLY1305_STATE
#define THIS_NETTLE_CHACHA_POLY1305_STATE ((struct Nettle_CHACHA_POLY1305_State_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_NETTLE_CHACHA_POLY1305_STATE
#define OBJ2_NETTLE_CHACHA_POLY1305_STATE(o) ((struct Nettle_CHACHA_POLY1305_State_struct *)(o->storage+Nettle_CHACHA_POLY1305_State_storage_offset))

#undef GET_NETTLE_CHACHA_POLY1305_STATE_STORAGE
#define GET_NETTLE_CHACHA_POLY1305_STATE_STORAGE(o) ((struct Nettle_CHACHA_POLY1305_State_struct *)(o->storage+Nettle_CHACHA_POLY1305_State_storage_offset)
static ptrdiff_t Nettle_CHACHA_POLY1305_State_storage_offset;
struct Nettle_CHACHA_POLY1305_State_struct {

#ifdef var_chacha_poly1305_Nettle_CHACHA_POLY1305_State_defined
#line 64 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
struct chacha_poly1305_ctx chacha_poly1305;
#endif /* var_chacha_poly1305_Nettle_CHACHA_POLY1305_State_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct Nettle_CHACHA_POLY1305_State_struct *Nettle_CHACHA_POLY1305_State_gdb_dummy_ptr;
#endif

#undef internal_init_Nettle_CHACHA_POLY1305_State_defined
#define internal_init_Nettle_CHACHA_POLY1305_State_defined

#undef Nettle_CHACHA_POLY1305_State_event_handler_defined
#define Nettle_CHACHA_POLY1305_State_event_handler_defined
static void init_Nettle_CHACHA_POLY1305_State_struct(void)
#line 67 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
{
struct Nettle_AEAD_State_struct *state;
ASSIGN_CURRENT_STORAGE(state, struct Nettle_AEAD_State_struct, 1,
Nettle_AEAD_State_program);
state->ctx = &THIS->chacha_poly1305;
}

#ifdef Nettle_CHACHA_POLY1305_State_event_handler_defined
static void Nettle_CHACHA_POLY1305_State_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_Nettle_CHACHA_POLY1305_State_defined
  case PROG_EVENT_INIT: init_Nettle_CHACHA_POLY1305_State_struct(); break;

#endif /* internal_init_Nettle_CHACHA_POLY1305_State_defined */
  default: break; 
  }
}

#endif /* Nettle_CHACHA_POLY1305_State_event_handler_defined */
/*! @endclass State
*/


#ifdef Nettle_CHACHA_POLY1305_event_handler_defined
static void Nettle_CHACHA_POLY1305_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_Nettle_CHACHA_POLY1305_defined
  case PROG_EVENT_INIT: init_Nettle_CHACHA_POLY1305_struct(); break;

#endif /* internal_init_Nettle_CHACHA_POLY1305_defined */
  default: break; 
  }
}

#endif /* Nettle_CHACHA_POLY1305_event_handler_defined */
/*! @endclass CHACHA_POLY1305
*/

#line 82 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
#line 589 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"




#line 593 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
#endif /* CHACHA_POLY1305_NONCE_SIZE == 12 */

#endif /* HAVE_NETTLE_CHACHA_POLY1305_H */

/*! @endmodule Nettle */

void
aead_init(void)
{

#ifdef module_strings_declared
module_strings[0] = 
  make_shared_binary_string("State",
                            CONSTANT_STRLEN("State"));
module_strings[1] = 
  make_shared_binary_string("__builtin.Nettle.AEAD",
                            CONSTANT_STRLEN("__builtin.Nettle.AEAD"));
#endif

#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
set_program_id_to_id( ___cmod_map_program_ids );

#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */

#ifdef class_Nettle_AEAD_defined

#ifdef PROG_NETTLE_AEAD_ID
#line 93 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  START_NEW_PROGRAM_ID(NETTLE_AEAD);
#else
#line 93 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  start_new_program();

#endif /* PROG_NETTLE_AEAD_ID */
#line 93 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Nettle_AEAD_program = Pike_compiler->new_program;

#ifndef tObjImpl_NETTLE_AEAD

#undef tObjIs_NETTLE_AEAD
#define tObjIs_NETTLE_AEAD "\3\1\177\0\0\2"

#undef tObjImpl_NETTLE_AEAD
#define tObjImpl_NETTLE_AEAD "\3\0\177\0\0\2"

#endif /* tObjImpl_NETTLE_AEAD */

#ifdef THIS_NETTLE_AEAD
  Nettle_AEAD_storage_offset = ADD_STORAGE(struct Nettle_AEAD_struct);
#endif /* THIS_NETTLE_AEAD */

#ifdef inherit_cq__22__builtin_2ENettle_2EAEAD_22_Nettle_AEAD_defined
#line 97 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Nettle_AEAD_cq__22__builtin_2ENettle_2EAEAD_22_inh_num = Pike_compiler->new_program->num_inherits;
  do {
#line 97 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    struct program *p = resolve_program(module_strings[1] /* "__builtin.Nettle.AEAD" */);
    if (p) {
#line 97 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
      low_inherit(p, NULL, -1, 0, 0, NULL);
#line 97 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
      Nettle_AEAD_cq__22__builtin_2ENettle_2EAEAD_22_inh_offset = Pike_compiler->new_program->inherits[Nettle_AEAD_cq__22__builtin_2ENettle_2EAEAD_22_inh_num].identifier_level;
#line 97 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
      free_program(p);
    } else {
#line 97 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
      yyerror("Inherit failed.");
    }
  } while(0);
#endif /* inherit_cq__22__builtin_2ENettle_2EAEAD_22_Nettle_AEAD_defined */

#ifdef class_Nettle_AEAD_State_defined

#ifdef PROG_NETTLE_AEAD_STATE_ID
#line 184 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  START_NEW_PROGRAM_ID(NETTLE_AEAD_STATE);
#else
#line 184 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  start_new_program();

#endif /* PROG_NETTLE_AEAD_STATE_ID */
#line 184 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Nettle_AEAD_State_program = Pike_compiler->new_program;

#ifndef tObjImpl_NETTLE_AEAD_STATE

#undef tObjIs_NETTLE_AEAD_STATE
#define tObjIs_NETTLE_AEAD_STATE "\3\1\177\0\0\3"

#undef tObjImpl_NETTLE_AEAD_STATE
#define tObjImpl_NETTLE_AEAD_STATE "\3\0\177\0\0\3"

#endif /* tObjImpl_NETTLE_AEAD_STATE */

#ifdef THIS_NETTLE_AEAD_STATE
  Nettle_AEAD_State_storage_offset = ADD_STORAGE(struct Nettle_AEAD_State_struct);
#endif /* THIS_NETTLE_AEAD_STATE */

#ifdef extra_Nettle_AEAD_State_defined
#line 191 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
{
/* Perform an inherit of the State class (if any) that our parent
       * may contain via its inherit of __builtin.Nettle.AEAD.
       */
struct program *parent_prog = Pike_compiler->previous->new_program;
struct object *parent_obj = Pike_compiler->previous->fake_object;
int parent_State_fun_num =
really_low_find_shared_string_identifier(module_strings[0] /* "State" */,
parent_prog,
SEE_PROTECTED|SEE_PRIVATE);
if (parent_State_fun_num >= 0) {
struct program *parent_State_prog =
low_program_from_function(parent_obj, parent_State_fun_num);
if (parent_State_prog) {
parent_State_fun_num =
really_low_reference_inherited_identifier(Pike_compiler->previous,
0, parent_State_fun_num);
low_inherit(parent_State_prog, 0,
parent_State_fun_num,
1 + 42, 0, NULL);
}
}
}


#endif /* extra_Nettle_AEAD_State_defined */

#ifdef Nettle_AEAD_State_event_handler_defined
  pike_set_prog_event_callback(Nettle_AEAD_State_event_handler);

#ifndef Nettle_AEAD_State_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* Nettle_AEAD_State_gc_live_obj */

#endif /* Nettle_AEAD_State_event_handler_defined */

#ifdef f_Nettle_AEAD_State_set_encrypt_key_defined

#ifdef f_Nettle_AEAD_State_set_encrypt_key_fun_num_used
  f_Nettle_AEAD_State_set_encrypt_key_fun_num =
#endif /* f_Nettle_AEAD_State_set_encrypt_key_fun_num_used */
#line 242 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("set_encrypt_key", f_Nettle_AEAD_State_set_encrypt_key, tFunc(tStr8 tOr(tInt, tVoid), tObjImpl_NETTLE_CIPHER_STATE), 0, OPT_SIDE_EFFECT);

#endif /* f_Nettle_AEAD_State_set_encrypt_key_defined */

#ifdef f_Nettle_AEAD_State_set_decrypt_key_defined

#ifdef f_Nettle_AEAD_State_set_decrypt_key_fun_num_used
  f_Nettle_AEAD_State_set_decrypt_key_fun_num =
#endif /* f_Nettle_AEAD_State_set_decrypt_key_fun_num_used */
#line 269 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("set_decrypt_key", f_Nettle_AEAD_State_set_decrypt_key, tFunc(tStr8 tOr(tInt, tVoid), tObjImpl_NETTLE_CIPHER_STATE), 0, OPT_SIDE_EFFECT);

#endif /* f_Nettle_AEAD_State_set_decrypt_key_defined */

#ifdef f_Nettle_AEAD_State_make_key_defined

#ifdef f_Nettle_AEAD_State_make_key_fun_num_used
  f_Nettle_AEAD_State_make_key_fun_num =
#endif /* f_Nettle_AEAD_State_make_key_fun_num_used */
#line 299 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("make_key", f_Nettle_AEAD_State_make_key, tFunc(tNone,tStr8), 0, OPT_EXTERNAL_DEPEND);

#endif /* f_Nettle_AEAD_State_make_key_defined */

#ifdef f_Nettle_AEAD_State_crypt_defined

#ifdef f_Nettle_AEAD_State_crypt_fun_num_used
  f_Nettle_AEAD_State_crypt_fun_num =
#endif /* f_Nettle_AEAD_State_crypt_fun_num_used */
#line 325 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("crypt", f_Nettle_AEAD_State_crypt, tFunc(tStr8,tStr8), 0, OPT_EXTERNAL_DEPEND | OPT_SIDE_EFFECT);

#endif /* f_Nettle_AEAD_State_crypt_defined */

#ifdef f_Nettle_AEAD_State_name_defined

#ifdef f_Nettle_AEAD_State_name_fun_num_used
  f_Nettle_AEAD_State_name_fun_num =
#endif /* f_Nettle_AEAD_State_name_fun_num_used */
#line 359 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("name", f_Nettle_AEAD_State_name, tFunc(tNone,tStr8), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_State_name_defined */

#ifdef f_Nettle_AEAD_State_digest_size_defined

#ifdef f_Nettle_AEAD_State_digest_size_fun_num_used
  f_Nettle_AEAD_State_digest_size_fun_num =
#endif /* f_Nettle_AEAD_State_digest_size_fun_num_used */
#line 369 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("digest_size", f_Nettle_AEAD_State_digest_size, tFunc(tNone,"\10\0\0\0\0\177\377\377\377"), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_State_digest_size_defined */

#ifdef f_Nettle_AEAD_State_key_size_defined

#ifdef f_Nettle_AEAD_State_key_size_fun_num_used
  f_Nettle_AEAD_State_key_size_fun_num =
#endif /* f_Nettle_AEAD_State_key_size_fun_num_used */
#line 380 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("key_size", f_Nettle_AEAD_State_key_size, tFunc(tNone,"\10\0\0\0\0\177\377\377\377"), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_State_key_size_defined */

#ifdef f_Nettle_AEAD_State_block_size_defined

#ifdef f_Nettle_AEAD_State_block_size_fun_num_used
  f_Nettle_AEAD_State_block_size_fun_num =
#endif /* f_Nettle_AEAD_State_block_size_fun_num_used */
#line 395 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("block_size", f_Nettle_AEAD_State_block_size, tFunc(tNone,"\10\0\0\0\0\177\377\377\377"), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_State_block_size_defined */

#ifdef f_Nettle_AEAD_State_iv_size_defined

#ifdef f_Nettle_AEAD_State_iv_size_fun_num_used
  f_Nettle_AEAD_State_iv_size_fun_num =
#endif /* f_Nettle_AEAD_State_iv_size_fun_num_used */
#line 407 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("iv_size", f_Nettle_AEAD_State_iv_size, tFunc(tNone,"\10\0\0\0\0\177\377\377\377"), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_State_iv_size_defined */

#ifdef f_Nettle_AEAD_State_set_iv_defined

#ifdef f_Nettle_AEAD_State_set_iv_fun_num_used
  f_Nettle_AEAD_State_set_iv_fun_num =
#endif /* f_Nettle_AEAD_State_set_iv_fun_num_used */
#line 421 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("set_iv", f_Nettle_AEAD_State_set_iv, tFunc(tStr8, tObjImpl_NETTLE_MAC_STATE), 0, OPT_SIDE_EFFECT);

#endif /* f_Nettle_AEAD_State_set_iv_defined */

#ifdef f_Nettle_AEAD_State_update_defined

#ifdef f_Nettle_AEAD_State_update_fun_num_used
  f_Nettle_AEAD_State_update_fun_num =
#endif /* f_Nettle_AEAD_State_update_fun_num_used */
#line 457 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("update", f_Nettle_AEAD_State_update, tFunc(tStr8, tObjImpl_NETTLE_MAC_STATE), 0, OPT_SIDE_EFFECT);

#endif /* f_Nettle_AEAD_State_update_defined */

#ifdef f_Nettle_AEAD_State_digest_defined

#ifdef f_Nettle_AEAD_State_digest_fun_num_used
  f_Nettle_AEAD_State_digest_fun_num =
#endif /* f_Nettle_AEAD_State_digest_fun_num_used */
#line 494 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("digest", f_Nettle_AEAD_State_digest, tFunc(tOr("\10\200\0\0\0\177\377\377\377",tVoid),tStr8), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Nettle_AEAD_State_digest_defined */
#line 185 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Pike_compiler->new_program->flags |= PROGRAM_USES_PARENT|PROGRAM_NEEDS_PARENT|PROGRAM_CLEAR_STORAGE;
#line 184 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Nettle_AEAD_State_program=end_program();
#line 184 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
#ifdef Nettle_AEAD_State_program_fun_num_used
Nettle_AEAD_State_program_fun_num=
#endif
 add_program_constant("State",Nettle_AEAD_State_program,0);

#endif /* class_Nettle_AEAD_State_defined */

#ifdef Nettle_AEAD_event_handler_defined
  pike_set_prog_event_callback(Nettle_AEAD_event_handler);

#ifndef Nettle_AEAD_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* Nettle_AEAD_gc_live_obj */

#endif /* Nettle_AEAD_event_handler_defined */

#ifdef f_Nettle_AEAD_name_defined

#ifdef f_Nettle_AEAD_name_fun_num_used
  f_Nettle_AEAD_name_fun_num =
#endif /* f_Nettle_AEAD_name_fun_num_used */
#line 106 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("name", f_Nettle_AEAD_name, tFunc(tNone,tStr8), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_name_defined */

#ifdef f_Nettle_AEAD_digest_size_defined

#ifdef f_Nettle_AEAD_digest_size_fun_num_used
  f_Nettle_AEAD_digest_size_fun_num =
#endif /* f_Nettle_AEAD_digest_size_fun_num_used */
#line 119 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("digest_size", f_Nettle_AEAD_digest_size, tFunc(tNone,"\10\0\0\0\0\177\377\377\377"), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_digest_size_defined */

#ifdef f_Nettle_AEAD_key_size_defined

#ifdef f_Nettle_AEAD_key_size_fun_num_used
  f_Nettle_AEAD_key_size_fun_num =
#endif /* f_Nettle_AEAD_key_size_fun_num_used */
#line 133 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("key_size", f_Nettle_AEAD_key_size, tFunc(tNone,"\10\0\0\0\0\177\377\377\377"), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_key_size_defined */

#ifdef f_Nettle_AEAD_block_size_defined

#ifdef f_Nettle_AEAD_block_size_fun_num_used
  f_Nettle_AEAD_block_size_fun_num =
#endif /* f_Nettle_AEAD_block_size_fun_num_used */
#line 151 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("block_size", f_Nettle_AEAD_block_size, tFunc(tNone,"\10\0\0\0\0\177\377\377\377"), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_block_size_defined */

#ifdef f_Nettle_AEAD_iv_size_defined

#ifdef f_Nettle_AEAD_iv_size_fun_num_used
  f_Nettle_AEAD_iv_size_fun_num =
#endif /* f_Nettle_AEAD_iv_size_fun_num_used */
#line 166 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    ADD_FUNCTION2("iv_size", f_Nettle_AEAD_iv_size, tFunc(tNone,"\10\0\0\0\0\177\377\377\377"), 0, OPT_TRY_OPTIMIZE);

#endif /* f_Nettle_AEAD_iv_size_defined */
#line 93 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Nettle_AEAD_program=end_program();
#line 93 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
#ifdef Nettle_AEAD_program_fun_num_used
Nettle_AEAD_program_fun_num=
#endif
 add_program_constant("AEAD",Nettle_AEAD_program,0);

#endif /* class_Nettle_AEAD_defined */

#ifdef class_Nettle_CHACHA_POLY1305_defined

#ifdef PROG_NETTLE_CHACHA_POLY1305_ID
#line 11 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  START_NEW_PROGRAM_ID(NETTLE_CHACHA_POLY1305);
#else
#line 11 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  start_new_program();

#endif /* PROG_NETTLE_CHACHA_POLY1305_ID */
#line 11 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Nettle_CHACHA_POLY1305_program = Pike_compiler->new_program;

#ifndef tObjImpl_NETTLE_CHACHA_POLY1305

#undef tObjIs_NETTLE_CHACHA_POLY1305
#define tObjIs_NETTLE_CHACHA_POLY1305 "\3\1\177\0\0\4"

#undef tObjImpl_NETTLE_CHACHA_POLY1305
#define tObjImpl_NETTLE_CHACHA_POLY1305 "\3\0\177\0\0\4"

#endif /* tObjImpl_NETTLE_CHACHA_POLY1305 */

#ifdef inherit_Nettle_AEAD_Nettle_CHACHA_POLY1305_defined
#line 15 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Nettle_CHACHA_POLY1305_Nettle_AEAD_inh_num = Pike_compiler->new_program->num_inherits;
#line 15 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  low_inherit(Nettle_AEAD_program, NULL, -1, 0, 0, NULL);
#line 15 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Nettle_CHACHA_POLY1305_Nettle_AEAD_inh_offset = Pike_compiler->new_program->inherits[Nettle_CHACHA_POLY1305_Nettle_AEAD_inh_num].identifier_level;

#endif /* inherit_Nettle_AEAD_Nettle_CHACHA_POLY1305_defined */

#ifdef class_Nettle_CHACHA_POLY1305_State_defined

#ifdef PROG_NETTLE_CHACHA_POLY1305_STATE_ID
#line 33 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  START_NEW_PROGRAM_ID(NETTLE_CHACHA_POLY1305_STATE);
#else
#line 33 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  start_new_program();

#endif /* PROG_NETTLE_CHACHA_POLY1305_STATE_ID */
#line 33 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
  Nettle_CHACHA_POLY1305_State_program = Pike_compiler->new_program;

#ifndef tObjImpl_NETTLE_CHACHA_POLY1305_STATE

#undef tObjIs_NETTLE_CHACHA_POLY1305_STATE
#define tObjIs_NETTLE_CHACHA_POLY1305_STATE "\3\1\177\0\0\5"

#undef tObjImpl_NETTLE_CHACHA_POLY1305_STATE
#define tObjImpl_NETTLE_CHACHA_POLY1305_STATE "\3\0\177\0\0\5"

#endif /* tObjImpl_NETTLE_CHACHA_POLY1305_STATE */

#ifdef THIS_NETTLE_CHACHA_POLY1305_STATE
  Nettle_CHACHA_POLY1305_State_storage_offset = ADD_STORAGE(struct Nettle_CHACHA_POLY1305_State_struct);
#endif /* THIS_NETTLE_CHACHA_POLY1305_STATE */

#ifdef extra_Nettle_CHACHA_POLY1305_State_defined
#line 40 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
{
/* Perform an inherit of the AEAD.State class that our parent
       * contains via its inherit of AEAD.
       */
struct program *parent_prog = Pike_compiler->previous->new_program;
struct object *parent_obj = Pike_compiler->previous->fake_object;
int parent_State_fun_num =
really_low_find_shared_string_identifier(module_strings[0] /* "State" */,
parent_prog,
SEE_PROTECTED|SEE_PRIVATE);
if (parent_State_fun_num >= 0) {
struct program *parent_State_prog =
low_program_from_function(parent_obj, parent_State_fun_num);
if (parent_State_prog) {
parent_State_fun_num =
really_low_reference_inherited_identifier(Pike_compiler->previous,
0, parent_State_fun_num);
low_inherit(parent_State_prog, 0,
parent_State_fun_num,
1 + 42, 0, NULL);
}
}
}


#endif /* extra_Nettle_CHACHA_POLY1305_State_defined */

#ifdef Nettle_CHACHA_POLY1305_State_event_handler_defined
  pike_set_prog_event_callback(Nettle_CHACHA_POLY1305_State_event_handler);

#ifndef Nettle_CHACHA_POLY1305_State_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* Nettle_CHACHA_POLY1305_State_gc_live_obj */

#endif /* Nettle_CHACHA_POLY1305_State_event_handler_defined */
#line 34 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
  Pike_compiler->new_program->flags |= PROGRAM_NEEDS_PARENT|PROGRAM_USES_PARENT;
#line 33 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
  Nettle_CHACHA_POLY1305_State_program=end_program();
#line 33 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
#ifdef Nettle_CHACHA_POLY1305_State_program_fun_num_used
Nettle_CHACHA_POLY1305_State_program_fun_num=
#endif
 add_program_constant("State",Nettle_CHACHA_POLY1305_State_program,0);

#endif /* class_Nettle_CHACHA_POLY1305_State_defined */

#ifdef Nettle_CHACHA_POLY1305_event_handler_defined
  pike_set_prog_event_callback(Nettle_CHACHA_POLY1305_event_handler);

#ifndef Nettle_CHACHA_POLY1305_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* Nettle_CHACHA_POLY1305_gc_live_obj */

#endif /* Nettle_CHACHA_POLY1305_event_handler_defined */
#line 11 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
  Nettle_CHACHA_POLY1305_program=end_program();
#line 11 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.H"
#ifdef Nettle_CHACHA_POLY1305_program_fun_num_used
Nettle_CHACHA_POLY1305_program_fun_num=
#endif
 add_program_constant("CHACHA_POLY1305",Nettle_CHACHA_POLY1305_program,0);

#endif /* class_Nettle_CHACHA_POLY1305_defined */

#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
set_program_id_to_id( 0 );
#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */
#line 602 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
;
}

void
aead_exit(void)
{

#ifdef class_Nettle_AEAD_defined

#ifdef class_Nettle_AEAD_State_defined
  if(Nettle_AEAD_State_program) {
#line 184 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    free_program(Nettle_AEAD_State_program);
    Nettle_AEAD_State_program=0;
  }

#endif /* class_Nettle_AEAD_State_defined */
  if(Nettle_AEAD_program) {
#line 93 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    free_program(Nettle_AEAD_program);
    Nettle_AEAD_program=0;
  }

#endif /* class_Nettle_AEAD_defined */

#ifdef class_Nettle_CHACHA_POLY1305_defined

#ifdef class_Nettle_CHACHA_POLY1305_State_defined
  if(Nettle_CHACHA_POLY1305_State_program) {
#line 33 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    free_program(Nettle_CHACHA_POLY1305_State_program);
    Nettle_CHACHA_POLY1305_State_program=0;
  }

#endif /* class_Nettle_CHACHA_POLY1305_State_defined */
  if(Nettle_CHACHA_POLY1305_program) {
#line 11 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
    free_program(Nettle_CHACHA_POLY1305_program);
    Nettle_CHACHA_POLY1305_program=0;
  }

#endif /* class_Nettle_CHACHA_POLY1305_defined */

#ifdef module_strings_declared
{
  int i;
  for(i=0; i < 2; i++) {
    if (module_strings[i]) free_string(module_strings[i]);
    module_strings[i] = NULL;
  }
}
#endif
#line 608 "/Users/hww3/devel/pike/src/post_modules/Nettle/aead.cmod"
;
}

#endif /* HAVE_LIBNETTLE */


#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
static int ___cmod_map_program_ids(int id)
{
  int i = 0;
  if( (id&0x7f000000) != 0x7f000000 ) return id;
  id = id&0x00ffffff;
#ifdef class_Nettle_CHACHA_POLY1305_defined
if(id==4) return Nettle_CHACHA_POLY1305_program->id;
#endif
#ifdef class_Nettle_CHACHA_POLY1305_State_defined
if(id==5) return Nettle_CHACHA_POLY1305_State_program->id;
#endif
#ifdef class_Nettle_AEAD_defined
if(id==2) return Nettle_AEAD_program->id;
#endif
#ifdef class_Nettle_AEAD_State_defined
if(id==3) return Nettle_AEAD_State_program->id;
#endif
  return 0;
}
#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */
