Blame cbits/cryptonite_aes.h

Packit 141393
/*
Packit 141393
 *	Copyright (C) 2008 Vincent Hanquez <tab@snarc.org>
Packit 141393
 *
Packit 141393
 * All rights reserved.
Packit 141393
 * 
Packit 141393
 * Redistribution and use in source and binary forms, with or without
Packit 141393
 * modification, are permitted provided that the following conditions
Packit 141393
 * are met:
Packit 141393
 * 1. Redistributions of source code must retain the above copyright
Packit 141393
 *    notice, this list of conditions and the following disclaimer.
Packit 141393
 * 2. Redistributions in binary form must reproduce the above copyright
Packit 141393
 *    notice, this list of conditions and the following disclaimer in the
Packit 141393
 *    documentation and/or other materials provided with the distribution.
Packit 141393
 * 3. Neither the name of the author nor the names of his contributors
Packit 141393
 *    may be used to endorse or promote products derived from this software
Packit 141393
 *    without specific prior written permission.
Packit 141393
 * 
Packit 141393
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 141393
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 141393
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 141393
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
Packit 141393
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 141393
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 141393
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 141393
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 141393
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 141393
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 141393
 * SUCH DAMAGE.
Packit 141393
 *
Packit 141393
 * AES implementation
Packit 141393
 */
Packit 141393
#ifndef CRYPTONITE_AES_H
Packit 141393
#define CRYPTONITE_AES_H
Packit 141393
Packit 141393
#include <stdint.h>
Packit 141393
#include "aes/block128.h"
Packit 141393
Packit 141393
typedef block128 aes_block;
Packit 141393
Packit 141393
/* size = 456 */
Packit 141393
typedef struct {
Packit 141393
	uint8_t nbr; /* number of rounds: 10 (128), 12 (192), 14 (256) */
Packit 141393
	uint8_t strength; /* 128 = 0, 192 = 1, 256 = 2 */
Packit 141393
	uint8_t _padding[6];
Packit 141393
	uint8_t data[16*14*2];
Packit 141393
} aes_key;
Packit 141393
Packit 141393
/* size = 4*16+2*8= 80 */
Packit 141393
typedef struct {
Packit 141393
	aes_block tag;
Packit 141393
	aes_block h;
Packit 141393
	aes_block iv;
Packit 141393
	aes_block civ;
Packit 141393
	uint64_t length_aad;
Packit 141393
	uint64_t length_input;
Packit 141393
} aes_gcm;
Packit 141393
Packit 141393
typedef struct {
Packit 141393
	block128 offset_aad;
Packit 141393
	block128 offset_enc;
Packit 141393
	block128 sum_aad;
Packit 141393
	block128 sum_enc;
Packit 141393
	block128 lstar;
Packit 141393
	block128 ldollar;
Packit 141393
	block128 li[4];
Packit 141393
} aes_ocb;
Packit 141393
Packit 141393
/* in bytes: either 16,24,32 */
Packit 141393
void cryptonite_aes_initkey(aes_key *ctx, uint8_t *key, uint8_t size);
Packit 141393
Packit 141393
void cryptonite_aes_encrypt(aes_block *output, aes_key *key, aes_block *input);
Packit 141393
void cryptonite_aes_decrypt(aes_block *output, aes_key *key, aes_block *input);
Packit 141393
Packit 141393
void cryptonite_aes_encrypt_ecb(aes_block *output, aes_key *key, aes_block *input, uint32_t nb_blocks);
Packit 141393
void cryptonite_aes_decrypt_ecb(aes_block *output, aes_key *key, aes_block *input, uint32_t nb_blocks);
Packit 141393
Packit 141393
void cryptonite_aes_encrypt_cbc(aes_block *output, aes_key *key, aes_block *iv, aes_block *input, uint32_t nb_blocks);
Packit 141393
void cryptonite_aes_decrypt_cbc(aes_block *output, aes_key *key, aes_block *iv, aes_block *input, uint32_t nb_blocks);
Packit 141393
Packit 141393
void cryptonite_aes_gen_ctr(aes_block *output, aes_key *key, const aes_block *iv, uint32_t nb_blocks);
Packit 141393
void cryptonite_aes_gen_ctr_cont(aes_block *output, aes_key *key, aes_block *iv, uint32_t nb_blocks);
Packit 141393
Packit 141393
void cryptonite_aes_encrypt_xts(aes_block *output, aes_key *key, aes_key *key2, aes_block *sector,
Packit 141393
                     uint32_t spoint, aes_block *input, uint32_t nb_blocks);
Packit 141393
void cryptonite_aes_decrypt_xts(aes_block *output, aes_key *key, aes_key *key2, aes_block *sector,
Packit 141393
                     uint32_t spoint, aes_block *input, uint32_t nb_blocks);
Packit 141393
Packit 141393
void cryptonite_aes_gcm_init(aes_gcm *gcm, aes_key *key, uint8_t *iv, uint32_t len);
Packit 141393
void cryptonite_aes_gcm_aad(aes_gcm *gcm, uint8_t *input, uint32_t length);
Packit 141393
void cryptonite_aes_gcm_encrypt(uint8_t *output, aes_gcm *gcm, aes_key *key, uint8_t *input, uint32_t length);
Packit 141393
void cryptonite_aes_gcm_decrypt(uint8_t *output, aes_gcm *gcm, aes_key *key, uint8_t *input, uint32_t length);
Packit 141393
void cryptonite_aes_gcm_finish(uint8_t *tag, aes_gcm *gcm, aes_key *key);
Packit 141393
Packit 141393
void cryptonite_aes_ocb_init(aes_ocb *ocb, aes_key *key, uint8_t *iv, uint32_t len);
Packit 141393
void cryptonite_aes_ocb_aad(aes_ocb *ocb, aes_key *key, uint8_t *input, uint32_t length);
Packit 141393
void cryptonite_aes_ocb_encrypt(uint8_t *output, aes_ocb *ocb, aes_key *key, uint8_t *input, uint32_t length);
Packit 141393
void cryptonite_aes_ocb_decrypt(uint8_t *output, aes_ocb *ocb, aes_key *key, uint8_t *input, uint32_t length);
Packit 141393
void cryptonite_aes_ocb_finish(uint8_t *tag, aes_ocb *ocb, aes_key *key);
Packit 141393
Packit 141393
#endif