Exemple #1
0
unsigned int KG_GenerateSymmetric(int level, char* encryption_template)
{
    char temp[512] = "";
    unsigned long i[4] = {0};
    CookText(temp, encryption_template);
    if(level >= 20)
    {
        GetKeyMD5(i, temp, 0);
        return (i[0] ^ i[1]);
    }
    return crc32(temp, strlen(temp), NewCRC32);
}
Exemple #2
0
void KG_GenerateEcdsaParameters(const char* encryptiontemplate, char* private_text, char* basepoint_text, char* public_x_text, char* public_y_text)
{
    EC_PARAMETER Base;
    EC_KEYPAIR Signer;
    ECC_POINT temp;
    char encryption_template[512];
    char rndinitstring[1024];
    unsigned long i[4];
    unsigned int basepointinit;
    BigInt test = BigInt_Create();
    BigInt secretkeyhash = BigInt_Create();
    BigInt prime_order = BigInt_Create();
    CookText(encryption_template, encryptiontemplate);
    md5(i, encryption_template, strlen(encryption_template));
    basepointinit = i[0];
    sprintf(basepoint_text, "%u", basepointinit);
    ECC_InitializeTable();
    BigInt_FromString(ECC_PRIMEORDER, 10, prime_order);
    BigIntToField(prime_order, &Base.pnt_order);
    Field_Clear(&Base.cofactor);
    Base.cofactor.e[ECC_NUMWORD] = 2;
    Base.crv.form = 1;
    Field_Set(&Base.crv.a2);
    Field_Set(&Base.crv.a6);
    InitRandomGenerator(basepointinit);
    ECC_RandomPoint(&temp, &Base.crv);
    ECC_PointDouble(&temp, &Base.pnt, &Base.crv);
    strcpy(rndinitstring, encryption_template);
    strcat(rndinitstring, "PVTKEY");
    BigInt_Hash(rndinitstring, strlen(rndinitstring), secretkeyhash);
    ECC_KeyGenerationPrimitive(&Base, &Signer, secretkeyhash);
    FieldToBigInt(&Signer.pblc_key.x, test);
    BigInt_ToString(test, 10, public_x_text);
    FieldToBigInt(&Signer.pblc_key.y, test);
    BigInt_ToString(test, 10, public_y_text);
    FieldToBigInt(&Signer.prvt_key, test);
    BigInt_ToString(test, 10, private_text);
    BigInt_Destroy(test);
    BigInt_Destroy(secretkeyhash);
    BigInt_Destroy(prime_order);
}
Exemple #3
0
char RetrieveKeyInfo(int level_input, const char* name_, unsigned long hardwareID, const char* origkey_, struct KeyInformation* keyinfo, HWND hwndDlg, UINT control_id)
{
    unsigned short keydatecreated=0, keyotherinfo[5]= {0,0,0,0,0};
    unsigned long keytemplateID=0;

    HWND log=(HWND)0;
    char log_msg[1024]="";
    char name[1024]="";
    char serial[1024]="";
    char* origkey=serial;
    strcpy(origkey, origkey_);
    strcpy(name, name_);
    bool firstlog=true;

    bool keystring=false;
    char keystring_text[256]="";

    struct CipherKeyStruct *cipherkey;
    char cooked[512]="";
    int x, v3=0, shortv3=0;
    int level=level_input;

    if(hwndDlg && control_id)
        log=GetDlgItem(hwndDlg, control_id);

    if(level>=14)
    {
        shortv3=1;
        level=level-13;
        //ShortV3 keys can have signature levels 1 through 10 now
        if(level<1 || level>10)
            return 0;
    }
    else if(level>=5)
    {
        v3=1; //TODO: remove?
        level=level-4;
        //V3 keys can now have signature levels 1 through 9
        if(level<1 || level>9)
            return 0;
    }
    else if(level!=0)
    {
        //V2 keys can only have signature levels 1 through 4
        if(level<1 || level>4)
            return 0;
    }

    bool key_appears_nameless=false;
    const char* nameless_check=origkey;
    while(*nameless_check=='0' || *nameless_check=='-')
        nameless_check++;
    if(*nameless_check=='2' && shortv3)
        key_appears_nameless=true;

    if(!name[0] || key_appears_nameless) //nameless key?
    {
        if(!shortv3)
        {
            AddLogMessage(log, "Only ShortV3 Keys can be nameless...", true);
            return 0;
        }
        //remove prepended zero bytes
        while(*origkey=='0' || *origkey=='-')
            origkey++;
        //check for the nameless identifier
        if(*origkey!='2')
        {
            AddLogMessage(log, "Key does not appear to be nameless...", true);
            return 0;
        }
        //retrieve the name
        int count1=0,count2=0;
        for(; count2<6; count1++)
            if(origkey[count1]!='-')
            {
                name[count2]=origkey[count1];
                count2++;
            }
        origkey+=count1;
        sprintf(log_msg, "Nameless Key:\r\nName=%s, Key=%s", name, origkey);
        AddLogMessage(log, log_msg, true);
        firstlog=false;
    }

    if(level==0) ///Analyse unsigned keys
    {
        unsigned long k[2]= {0};
        const char *c=origkey;
        int digits=0;
        char cc;
        while(digits<8 && *c)
        {
            cc=hexdigit(*c++);
            if(cc>=0)
            {
                digits++;
                k[0]=(k[0]<<4)|cc;
            }
        }
        while(digits<16 && *c)
        {
            cc=hexdigit(*c++);
            if(cc>=0)
            {
                digits++;
                k[1]=(k[1]<<4)|cc;
            }
        }
        if(log)
        {
            ByteArray2String((unsigned char*)k, log_msg, sizeof(unsigned long)*2, 20);
            AddLogMessage(log, "Enciphered KeyBytes (Len: 8):", true);
            AddLogMessage(log, log_msg, false);
        }
        CookText(cooked, name);
        cipherkey=CreateCipherKey(cooked, strlen(cooked));
        Decipher(cipherkey, (char*)k, sizeof(unsigned long)*2);
        if(log)
        {
            ByteArray2String((unsigned char*)k, log_msg, sizeof(unsigned long)*2, 20);
            AddLogMessage(log, "Deciphered KeyBytes:", false);
            AddLogMessage(log, log_msg, false);
        }
        ReleaseCipherKey(cipherkey);
        keytemplateID=k[0];
        keydatecreated=(unsigned short)(k[1]>>16);
        keyotherinfo[0]=(unsigned short)(k[1]&0xFFFF);
    }