/****************************************************************************/
/*	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		*/
/*	This software is released under the GNU General Public License, version	*/
/*	3, with the exemptions that 1) the header files installed by this 	 	*/
/*	package can be included in closed-source code and 2) the libraries		*/
/*	built by this package can be statically linked into a closed-source 	*/
/*	binary. See the file LICENSE for the details.							*/
/*	This software is provided "AS IS", without any warranty or guarantee.	*/
/*	By using this software you acknowledge that neither Bendor Research nor	*/
/*	any of its personnel or affiliates can be held liable for any damages,	*/
/*	including, but not limited to, loss of business, loss of money, loss of */
/*	life, loss of reputation, arising out of this software being faulty or	*/
/*	not performing as advertised, even if Bendor Research was aware of such	*/
/*	faults in the software. You use this software at your own risk, any and */
/*	all liabilities that arise out of your using this software are strictly	*/
/*	yours.																	*/
/****************************************************************************/

#ifndef _NANU_NANU_H
#define _NANU_NANU_H

#define	NANU_USE_LIBC	0
#define	NANU_USE_ASM	1

#define	NANU_ASM_SUB	NANU_USE_ASM
#define	NANU_ASM_ADD	NANU_USE_ASM
#define	NANU_ASM_MULS	NANU_USE_ASM
#define	NANU_ASM_MULU	NANU_USE_ASM
#define	NANU_ASM_MULR	NANU_USE_ASM
#define	NANU_ASM_MULM	NANU_USE_ASM

#ifndef	ASSEMBLY_SOURCE

#include <crypto/nanu.h>

/*
*	Error handling
*/

int			_bc_NanuError( BC_NANU nanu, int error );

/*
*	Variable management
*/

unsigned	*_bc_NanuVarPtr( BC_NANU nanu, int var );
unsigned	_bc_NanuVarLen( BC_NANU nanu, int var );
int			_bc_NanuVarNew( BC_NANU nanu, int size );
int			_bc_NanuVarCon( BC_NANU nanu, const BC_NANU_CONS *data );
void		_bc_NanuVarInc( BC_NANU nanu, int var );
void		_bc_NanuVarDec( BC_NANU nanu, int var );
int			_bc_NanuVarRes( BC_NANU nanu, int var, int size );
void		_bc_NanuVarNrm( BC_NANU nanu, int var );
int			_bc_NanuVarTmp( BC_NANU nanu, int var1, int var2, unsigned size );

/*
*	Stack management
*/

int			_bc_NanuStkPut( BC_NANU nanu, int var );
int			_bc_NanuStkGet( BC_NANU nanu );
int			_bc_NanuStkRol( BC_NANU nanu, int num );
int			_bc_NanuStkSee( BC_NANU nanu, unsigned num );

/*
*	Low level memory functions
*/

void		_bc_NanuZero( unsigned *p, unsigned l );
void		_bc_NanuMove( unsigned *d, unsigned *s, unsigned l );

/*
*	Low level multiprecision operations and special fast functions
*/

unsigned	_bc_NanuAdd2( unsigned *r, unsigned *a, unsigned *b, unsigned l );
unsigned	_bc_NanuAdd1( unsigned *r, unsigned *a, unsigned s, unsigned l );
unsigned	_bc_NanuSub2( unsigned *r, unsigned *a, unsigned *b, unsigned l );
unsigned	_bc_NanuSub1( unsigned *r, unsigned *a, unsigned s, unsigned l );
unsigned	_bc_NanuMulu( unsigned *r, unsigned *a, unsigned b, unsigned l );
int			_bc_NanuComp( unsigned *a, unsigned *b, unsigned l );

long long _bc_NanuMuls( unsigned *R, unsigned *M, unsigned q, unsigned l );
unsigned long long _bc_NanuMulr( unsigned *R, unsigned *Y, unsigned x,
								 unsigned l, unsigned s );
unsigned	_bc_NanuMulm( unsigned *R, unsigned *A, unsigned *M,
						  unsigned t, unsigned b, unsigned f,
						  unsigned al, unsigned l );

/*
*	Other shared functions
*/

int		_bc_NanuMmul( BC_NANU nanu, int aop, int bob, int mod );

#endif
#endif

