Esempio n. 1
0
int main()
{
 int L,n=10,Mq=0;
 spis *p;
 printf("byte 2 or 4 - ");
 scanf("%d",&L);
 if ((L!=2)&(L!=4)) return 0;
 p=SpisRand(n,100);
 list(p);
 printf("\n");
 printf(" sum = %d, RunNumber= %d\n",sum(p),RunNumber(p));
 DigitalSortInc(p,L);
 list(p); 
 printf("\n"); 
 printf(" sum = %d, RunNumber= %d\n\n",sum(p),RunNumber(p));
 p=SpisRand(n,100);
 list(p);
 printf("\n"); 
 printf(" sum = %d, RunNumber= %d\n",sum(p),RunNumber(p)); 
 DigitalSortDec(p,L);
 list(p);
 printf("\n");  
 printf(" sum = %d, RunNumber= %d\n\n",sum(p),RunNumber(p)); 
 int cur,prev,qtime;
 n=10000000;
 FillRand(A,n);
 //cur=prev=GetTickCount();
 QuickSort(A,0,n-1);
 //cur=GetTickCount();
 qtime=cur-prev;
 printf("QuickSort %d - msec\n",qtime);
 int k=100,l=2;
 while (k<100000000) {
        //prev=GetTickCount();
        p=SpisRand(n,k);
        DigitalSortInc(p,l);
      //  cur=GetTickCount();
        printf("%d - %d msec\n",l,cur-prev);
        l++;
        k*=10;
 }
 system("pause");

}
Esempio n. 2
0
/*
	[MS-OFFCRYPTO] 2.3.4.14
*/
inline void GenerateIntegrityParameter(
	std::string& encryptedHmacKey,
	std::string& encryptedHmacValue,
	const std::string& encryptedPackage,
	const CipherParam& keyData,
	const std::string& secretKey,
	const std::string& saltValue)
{
	std::string salt;
	FillRand(salt, keyData.hashSize);
#ifdef SAME_KEY
	salt = fromHex("C9FACA5436849906B600DE95E155B47A01ABEDD0");
#endif
	const std::string iv1 = generateIv(keyData, ms::blkKey_dataIntegrity1, saltValue);
	const std::string iv2 = generateIv(keyData, ms::blkKey_dataIntegrity2, saltValue);
	encryptedHmacKey = cipher(keyData.cipherName, salt, secretKey, iv1, cybozu::crypto::Cipher::Encoding);
	cybozu::crypto::Hmac hmac(keyData.hashName);
	std::string ret = hmac.eval(salt, encryptedPackage);
	encryptedHmacValue = cipher(keyData.cipherName, ret, secretKey, iv2, cybozu::crypto::Cipher::Encoding);
}
Esempio n. 3
0
inline bool encode_in(
	std::string& encryptedPackage,
	EncryptionInfo& info,
	const std::string& data,
	cybozu::crypto::Cipher::Name cipherName,
	cybozu::crypto::Hash::Name hashName,
	int spinCount,
	const std::string& pass,
	const std::string& masterKey)
{
	if (spinCount > 10000000) throw cybozu::Exception("ms:encode_in:too large spinCount") << spinCount;
	CipherParam& keyData = info.keyData;
	CipherParam& encryptedKey = info.encryptedKey;

	keyData.setByName(cipherName, hashName);
	encryptedKey.setByName(cipherName, hashName);
	info.spinCount = spinCount;

	std::string& iv = encryptedKey.saltValue;
	FillRand(iv, encryptedKey.saltSize);
#ifdef SAME_KEY
	puts("QQQ defined SAME_KEY QQQ");
	iv = fromHex("F4994F9B2DCD5E0E84BC6386D4523D2C");
#endif
	const std::string pwHash = hashPassword(encryptedKey.hashName, iv, pass, spinCount);

	const std::string skey1 = generateKey(encryptedKey, pwHash, blkKey_VerifierHashInput);
	const std::string skey2 = generateKey(encryptedKey, pwHash, blkKey_encryptedVerifierHashValue);
	const std::string skey3 = generateKey(encryptedKey, pwHash, blkKey_encryptedKeyValue);

	std::string verifierHashInput;
	FillRand(verifierHashInput, encryptedKey.saltSize);
#ifdef SAME_KEY
	verifierHashInput = fromHex("FEDAECD950F9E82C47CADA29B7837C6D");
#endif

	verifierHashInput.resize(RoundUp(verifierHashInput.size(), encryptedKey.blockSize));

	info.encryptedVerifierHashInput = cipher(encryptedKey.cipherName, verifierHashInput, skey1, iv, cybozu::crypto::Cipher::Encoding);
	std::string hashedVerifier = cybozu::crypto::Hash::digest(encryptedKey.hashName, verifierHashInput);
	hashedVerifier.resize(RoundUp(hashedVerifier.size(), encryptedKey.blockSize));

	info.encryptedVerifierHashValue = cipher(encryptedKey.cipherName, hashedVerifier, skey2, iv, cybozu::crypto::Cipher::Encoding);

	std::string secretKey;
	FillRand(secretKey, encryptedKey.saltSize);
#ifdef SAME_KEY
	secretKey = fromHex("BF44FBB51BE1E88BF130156E117E7900");
#endif
	if (!masterKey.empty()) {
		secretKey = masterKey;
	}
	normalizeKey(secretKey, encryptedKey.keyBits / 8);

	info.encryptedKeyValue = cipher(encryptedKey.cipherName, secretKey, skey3, iv, cybozu::crypto::Cipher::Encoding);

	FillRand(keyData.saltValue, keyData.saltSize);
#ifdef SAME_KEY
	keyData.saltValue = fromHex("C49AAAEE99004C6B017EE5CD11B86729");
#endif

	EncContent(encryptedPackage, data, encryptedKey, secretKey, keyData.saltValue);

	GenerateIntegrityParameter(info.encryptedHmacKey, info.encryptedHmacValue, encryptedPackage, keyData, secretKey, keyData.saltValue);
	return true;
}