bool KG_GeneratePvtY(int level, char* keytemplate, char* pvt_text, char* y_text) { char tmp[256] = ""; BigInt p, p1, pub, pvt, y, temp, temp2; int size, keysystem; if(level == 29) { char basepoint_text[10] = "", public_x_text[100] = "", public_y_text[100] = ""; KG_GenerateEcdsaParameters(keytemplate, pvt_text, basepoint_text, public_x_text, public_y_text); sprintf(y_text, "%s,%s,%s", basepoint_text, public_x_text, public_y_text); return true; } else if(level >= 20) { keysystem = KS_SHORTV3; level = level - 20; if(level > 8) return false; } else if(level >= 10) { keysystem = KS_V3; level = level - 10; if(level > 8) return false; } else { keysystem = KS_V2; if(level<0 or level>3) return false; } size = level + 4; p = BigInt_Create(); p1 = BigInt_Create(); pub = BigInt_Create(); pvt = BigInt_Create(); y = BigInt_Create(); temp = BigInt_Create(); temp2 = BigInt_Create(); BigInt_Set(temp, 1); BigInt_Shift(temp, size * 8, p); BigInt_Set(temp, primeoffsets[level]); BigInt_Add(p, temp, temp2); BigInt_Copy(p, temp2); BigInt_Subtract(p, BigInt_One(), p1); sprintf(tmp, "%u Level Public Key", level); GenerateKeyNumberFromString(tmp, p, &pub, keysystem, ((keysystem == KS_V3 || keysystem == KS_SHORTV3) ? level + 1 : 0)); GenerateKeyNumberFromString(keytemplate, p, &pvt, keysystem, ((keysystem == KS_V3 || keysystem == KS_SHORTV3) ? level + 1 : 0)); BigInt_ToString(pvt, 16, pvt_text); BigInt_PowerModulus(pub, pvt, p, y); BigInt_ToString(y, 16, y_text); BigInt_Destroy(temp2); BigInt_Destroy(temp); BigInt_Destroy(y); BigInt_Destroy(pvt); BigInt_Destroy(pub); BigInt_Destroy(p1); BigInt_Destroy(p); return true; }
void BigInt_Power(BigInt n, BigInt exp, BigInt answer) { BigInt_PowerModulus(n, exp, 0, answer); }