/*
 *               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.
 *
 */

#include <string.h>
#include <types.h>
#include <root.h>
#include "nvm.h"

#if defined(NC_BETA_PKI)
    u8 rootExp[] = 
        NC_BETA_PKI_EXP;

    u8 rootKey[] = 
        NC_BETA_PKI_MOD;

    const char* nvDefaultPki = NC_BPKI;

#else
    u8 rootExp[] = 
        DEFAULT_PKI_EXP;
        
    u8 rootKey[] = 
        DEFAULT_PKI_MOD;

    const char* nvDefaultPki = DEFAULT_PKI;

#endif

typedef struct {
    char* pki;
    u8* rExp;
    u8* rKey;
} nvPkiData;

u8 ncBetaPkiMod[] = NC_BETA_PKI_MOD;
u8 ncBetaPkiExp[] = NC_BETA_PKI_EXP;
u8 ncProdPkiMod[] = NC_PROD_PKI_MOD;
u8 ncProdPkiExp[] = NC_PROD_PKI_EXP;
u8 rvBetaPkiMod[] = RVL_DEVEL_PKI_MOD;
u8 rvBetaPkiExp[] = RVL_DEVEL_PKI_EXP;
u8 rvProdPkiMod[] = RVL_PROD_PKI_MOD;
u8 rvProdPkiExp[] = RVL_PROD_PKI_EXP;

nvPkiData pkiData[] =
{
    { NC_BPKI, ncBetaPkiExp, ncBetaPkiMod },
    { NC_PPKI, ncProdPkiExp, ncProdPkiMod },
    { RV_BPKI, rvBetaPkiExp, rvBetaPkiMod },
    { RV_PPKI, rvProdPkiExp, rvProdPkiMod }
};

int
nvSetRoot(const char* pki)
{
    int i;
    for (i = 0; i < sizeof(pkiData)/sizeof(pkiData[0]); i++) {
        if (strcasecmp(pki, pkiData[i].pki) == 0) {
            memcpy(rootExp, pkiData[i].rExp, sizeof(rootExp));
            memcpy(rootKey, pkiData[i].rKey, sizeof(rootKey));
            return 0;
        }
    }
    return -1;
}
