/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */

/* 
 * Utilities used in bsl.c
 */

#include <types.h>
#include <csl.h>
#include <bsl.h>
#include <ioslibc.h>
#include <sha1.h>
#include <aes.h>
#include "keystore.h"
#include <iosccert.h>

#ifndef __BSLUTILS_H__
#define __BSLUTILS_H__


/* 
 * Not exposed
 */

#define BSL_TYPE_SHIFT 4
#define BSL_TYPE_MASK 0xf0
#define BSL_SUBTYPE_MASK 0x0f
#define BSL_MAXRAND_BYTES 32
#define BSL_MAXSECRET_BYTES 32
#define BSL_SHAHASH_WORDS 5
#define BSL_SHABLOCK_WORDS 16

#define BSL_PROT_NO_EXPORT 0
#define BSL_PROT_PTXT_EXPORT 1
#define BSL_PROT_ENC_EXPORT 2


#define BSL_MAX_DEFAULT_HANDLES    11

typedef struct {
  u32 digest[5];          /* message digest */
  u32 count_lo, count_hi; /* 64-bit bit count */
  u32 data[16];           /* SHA data buffer */
} BSLShaHwContext;


IOSCError
getSizeFromType(u8 keytype, u8 keysubtype, u32 *keySize);

u32 
getExpSize(CSLOSRsaExponent exponent, u32 maxSize);

void
getKeyTypeSubtype(IOSCKeyHandle handle, 
                  u8 *keytype, 
                  u8 *keysubtype);

int
computeHMAC(u8 * context,
	    void * inputData, 
            u32 inputSize, 
            void *customData, 
            u32 customDataSize, 
            CSLOSHMACKey hmackey,  
	    u32 chainingFlag,
            void * signData);

unsigned char
computeRand();

unsigned long int 
wordswap(unsigned long int input);


int
generateUnsignedCert(const char* certName, const char* issuerName, IOSCCertSigType sigType, IOSCCertPubKeyType keyType, u8* pubKey, u8* exponent, int exponentSizeInBytes, u32 date, u8* cert);

IOSCError 
extractRandoms(u8 *iv, u8 *rand,  u32 size, IOSCSecretKeyHandle handle);


#endif
