Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions lib/testVectors/conformanceVectors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Cryptographic Conformance Test Vectors

This directory contains known-answer test vectors for validating CryptoViz cipher implementations against authoritative standards.

## Format

Vectors follow the `TestVectorSet` schema defined in `lib/testing/testVectorFormat.ts`:

```json
{
"algorithm": "aes",
"variant": "128",
"vectors": [
{
"testId": "unique-id",
"inputs": {
"key": "hex-string",
"plaintext": "hex-string"
},
"expectedOutput": {
"ciphertext": "hex-string"
}
}
]
}
```

## Sources

- **AES**: FIPS 197 (Federal Information Processing Standards Publication 197)
- **SHA-256**: FIPS 180-4 (Secure Hash Standard)

## Adding New Vectors

1. Create `algorithm.json` in this directory
2. Follow the schema with proper metadata attribution
3. Run: `npm run conformance algorithm-name`

## Running Tests

```bash
# Run conformance for all algorithms
npm run conformance

# Run conformance for specific algorithm
npm run conformance aes

# Run full test suite (includes conformance)
npm test
```

## CI Integration

Conformance tests run automatically in CI via `npm test`.
39 changes: 39 additions & 0 deletions lib/testVectors/conformanceVectors/aes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"algorithm": "aes",
"variant": "128",
"schemaVersion": "1.0",
"metadata": {
"source": "FIPS 197",
"conformanceTarget": "FIPS 197: Advanced Encryption Standard"
},
"vectors": [
{
"testId": "FIPS197-AppendixC-AES128-1",
"inputs": {
"key": "2b7e151628aed2a6abf7158809cf4f3c",
"plaintext": "6bc1bee22e409f96e93d7e117393172a"
},
"expectedOutput": {
"ciphertext": "3ad77bb40d7a3660a89ecaf32466ef97"
},
"metadata": {
"source": "FIPS 197 Appendix C.1",
"keySize": 128,
"blockSize": 128
}
},
{
"testId": "FIPS197-AppendixC-AES128-2",
"inputs": {
"key": "2b7e151628aed2a6abf7158809cf4f3c",
"plaintext": "ae2d8a571e03ac9c9eb76fac45af8e51"
},
"expectedOutput": {
"ciphertext": "f5d3d58503b9699de785895a86fd28ce"
},
"metadata": {
"source": "FIPS 197 Appendix C.1"
}
}
]
}
37 changes: 37 additions & 0 deletions lib/testVectors/conformanceVectors/sha256.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"algorithm": "sha256",
"variant": "256",
"schemaVersion": "1.0",
"metadata": {
"source": "FIPS 180-4",
"conformanceTarget": "FIPS 180-4: Secure Hash Standard"
},
"vectors": [
{
"testId": "SHA256-FIPS180-4-A",
"inputs": {
"message": "abc",
"key": ""
},
"expectedOutput": {
"digest": "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
},
"metadata": {
"source": "FIPS 180-4 Appendix B.1"
}
},
{
"testId": "SHA256-FIPS180-4-B",
"inputs": {
"message": "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"key": ""
},
"expectedOutput": {
"digest": "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
},
"metadata": {
"source": "FIPS 180-4 Appendix B.2"
}
}
]
}
23 changes: 23 additions & 0 deletions lib/testVectors/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,27 @@ export function formatMismatchDiagnostic(result: VectorRunResult): string {
` expected: ${result.expectedHex}`,
` actual: ${result.actualHex}`,
].join("\n");
}

/**
* Run conformance tests for an algorithm
* @param algorithm - Algorithm to test
* @param variant - Algorithm variant
* @param vectorPath - Path to vector JSON file
* @param executor - Executor for the algorithm
*/
export async function runConformanceTest(
algorithm: string,
variant: string,
vectorPath: string,
executor: ConformanceExecutor
): Promise<ConformanceSummary> {
const { ConformanceHarness, ConformanceSummary } = await import('@/lib/testing/conformanceHarness');

// Dynamically import vector file
const vectorModule = await import(vectorPath);
const vectorSet = vectorModule.default || vectorModule;

const harness = new ConformanceHarness(algorithm, variant, executor);
return harness.runTestVectorSet(vectorSet);
}
Loading
Loading