/*
 * Copyright 2010 Trident Microsystems (Far East) Ltd. All rights reserved.
 * All prior copyright rights in this work and the accompanying software
 * products transferred to Trident Microsystems (Far East) Ltd. by written
 * agreement.
 */
/*****************************************************************************/
/* Copyright (c) 2010 NXP B.V.                                               */
/*                                                                           */
/* This program is free software; you can redistribute it and/or modify      */
/* it under the terms of the GNU General Public License as published by      */
/* the Free Software Foundation, using version 2 of the License.             */
/*                                                                           */
/* This program is distributed in the hope that it will be useful,           */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the              */
/* GNU General Public License for more details.                              */
/*                                                                           */
/* You should have received a copy of the GNU General Public License         */
/* along with this program; if not, write to the Free Software               */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307       */
/* USA.                                                                      */
/*                                                                           */
/*****************************************************************************/
/*

Rev Date        Author      Comments
--------------------------------------------------------------------------------
  1 20040917    amccurdy    Original created
  3 20080215    batelaan    Update file copyright/license text
  4 20080321    amccurdy    Resync with svn
  5 20090225    amccurdy    Resync with svn
--------------------------------------------------------------------------------
*/

#ifndef _ABN_H_
#define _ABN_H_

#include <openssl/bn.h>

#include "aimage.h"

#define ABN_HEX_DIGITS_PER_WORD 	8
#define ABN_BITS_PER_WORD		32

extern void abn_init (unsigned int *bn, unsigned int initval, int words);
extern void abn_init_64 (unsigned int *bn, unsigned long long initval, int words);
extern int abn_init_from_string_hex (unsigned int *bn, char *hexstring, int words);
extern unsigned int abn_extract_lsbyte (unsigned int *bn, int words);
extern unsigned int abn_extract_msbyte (unsigned int *bn, int words);
extern void abn_print (char *prefix, unsigned int *bn, char *suffix, int words);
extern void abn_print_nlz (char *prefix, unsigned int *bn, char *suffix, int words);
extern void abn_print_nlz_nsp (char *prefix, unsigned int *bn, char *suffix, int words);
extern void abn_shift_left (unsigned int *bn, unsigned int bits, unsigned int carry, int words);
extern void abn_shift_right (unsigned int *bn, unsigned int bits, int words);
extern void abn_shift_left_single (unsigned int *bn, unsigned int carry, int words);
extern void abn_shift_right_single (unsigned int *bn, int words);
extern int abn_cmp (unsigned int *bn1, unsigned int *bn2, int words);
extern int abn_add (unsigned int *bn, unsigned int *q, int words);
extern int abn_sub (unsigned int *bn, unsigned int *q, int words);
extern BIGNUM *abn_to_opensslbn (unsigned int *bn, int words);
extern void opensslbn_to_abn (unsigned int *bn, BIGNUM *openssl_bn, int words);
extern unsigned int opensslbn_inverse_mod_two_tothepower_thirtytwo (BIGNUM *openssl_bn);
extern void abn_mont_mul (unsigned int *z, unsigned int *x, unsigned int *y, const aimage_keypub_t *key);
extern int abn_mont_exp (unsigned int *res, unsigned int *tmp, unsigned int *input, const aimage_keypub_t *key);

#endif

