/// <summary> /// Initialize crypto test vectors for AEAD tests /// </summary> private void InitializeCryptoVectorsAead() { int startIndex, resourceIndex = 0; CryptoVector CryptoVector; string rootKey, plainText, encryptionType, finalCellBlob; bool extractResult = false; while (resourceIndex < m_resource_data.Length) { // 1 - Extract RootKey from the resource text file. extractResult = ExtractCryptoParameter(m_resource_data, regexRootKeyIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(!extractResult || resourceIndex >= startIndex); // If input data is over, break. if (!extractResult) { break; } rootKey = m_resource_data.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(rootKey)); // 2 - Extract Plain Text from the resource text file. extractResult = ExtractCryptoParameter(m_resource_data, regexPlainTextIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(extractResult && resourceIndex >= startIndex); plainText = m_resource_data.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(plainText)); // 3 - Extract Test Encryption Type from the resource text file. extractResult = ExtractCryptoParameter(m_resource_data, regexEncryptionTypeIdentifier, regexEncryptionTypeDataIdentifier, regexEndParameterIdentifier, 0, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(extractResult && resourceIndex >= startIndex); encryptionType = m_resource_data.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(plainText)); // 4 - Extract Final Cell Value from the resource text file. extractResult = ExtractCryptoParameter(m_resource_data, regexFinalCellIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(extractResult && resourceIndex >= startIndex); finalCellBlob = m_resource_data.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(finalCellBlob)); // 5 - Instantiate a new crypto vector with these parameters and add it to the vector list. CryptoVector = new CryptoVector(StringToByteArray(rootKey), StringToByteArray(plainText), StringToByteArray(finalCellBlob), (CryptoVectorEncryptionType)Enum.Parse(typeof(CryptoVectorEncryptionType), encryptionType, ignoreCase: true)); m_CryptoVectors.Add(CryptoVector); } }
/// <summary> /// Initialize RSA test vector data /// </summary> private void InitializeCryptoVectorsRsa() { int startIndex, resourceIndex = 0; CryptoVector CryptoVector; string keyPair, plaintextCek, ciphertextCek, hashedCek, signedCek, pathCek, finalcellCek; bool extractResult = false; // 1 - Extract RSA Key pair from the resource text file. extractResult = ExtractCryptoParameter(m_resource_data_rsa, regexKeyPairIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(!extractResult || resourceIndex >= startIndex); // If input data is over, break. if (!extractResult) { return; } keyPair = m_resource_data_rsa.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(keyPair)); CryptoVector = new CryptoVector(StringToByteArray(keyPair), CryptNativeTestVectorType.RsaKeyPair); m_CryptoVectors.Add(CryptoVector); // 1a - Extract a matching PFX from the resource text file. extractResult = ExtractCryptoParameter(m_resource_data_rsa, regexPfxIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(!extractResult || resourceIndex >= startIndex); // If input data is over, break. if (!extractResult) { return; } string pfx = m_resource_data_rsa.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(keyPair)); CryptoVector = new CryptoVector(StringToByteArray(pfx), CryptNativeTestVectorType.RsaPfx); m_CryptoVectors.Add(CryptoVector); while (resourceIndex < m_resource_data.Length) { // 2 - Extract Plain Text & ciphertext from the resource text file. extractResult = ExtractCryptoParameter(m_resource_data_rsa, regexPlaintextCekIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); if (!extractResult) { break; } Debug.Assert(extractResult && resourceIndex >= startIndex); plaintextCek = m_resource_data_rsa.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(plaintextCek)); extractResult = ExtractCryptoParameter(m_resource_data_rsa, regexCiphertextCekIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(extractResult && resourceIndex >= startIndex); ciphertextCek = m_resource_data_rsa.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(ciphertextCek)); extractResult = ExtractCryptoParameter(m_resource_data_rsa, regexPathCekIdentifier, regexEncryptionTypeDataPath, regexEndParameterIdentifier, 0, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(extractResult && resourceIndex >= startIndex); pathCek = m_resource_data_rsa.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(pathCek)); extractResult = ExtractCryptoParameter(m_resource_data_rsa, regexHashedCekIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(extractResult && resourceIndex >= startIndex); hashedCek = m_resource_data_rsa.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(hashedCek)); extractResult = ExtractCryptoParameter(m_resource_data_rsa, regexSignedCekIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(extractResult && resourceIndex >= startIndex); signedCek = m_resource_data_rsa.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(signedCek)); extractResult = ExtractCryptoParameter(m_resource_data_rsa, regexFinalcellCekCekIdentifier, regexdataIdentifier, regexEndParameterIdentifier, 2, resourceIndex, out startIndex, out resourceIndex); Debug.Assert(extractResult && resourceIndex >= startIndex); finalcellCek = m_resource_data_rsa.Substring(startIndex, resourceIndex - startIndex); Debug.Assert(!string.IsNullOrWhiteSpace(signedCek)); // 3 - Instantiate a new crypto vector with these parameters and add it to the vector list. CryptoVector = new CryptoVector( StringToByteArray(plaintextCek) , StringToByteArray(ciphertextCek) , StringToByteArray(hashedCek) , StringToByteArray(signedCek) , pathCek.Substring(2) , StringToByteArray(finalcellCek)); m_CryptoVectors.Add(CryptoVector); } }