| 67 | |
| 68 | |
| 69 | function testCipherMode(name, direction, cipher, iv, padding, data, expected) |
| 70 | { |
| 71 | let mode, result; |
| 72 | if (name == "GCM") { |
| 73 | mode = new GCM(cipher); |
| 74 | result = mode.process(data, undefined, iv, padding /* AAD */, direction == "encrypt"); |
| 75 | } |
| 76 | else { |
| 77 | mode = new Mode(name, cipher, iv, padding); |
| 78 | result = mode[direction](data); |
| 79 | } |
| 80 | |
| 81 | if (Bin.comp(result, expected) != 0) { |
| 82 | trace(`${name}.${direction} FAIL\n`); |
| 83 | trace("result = " + Hex.toString(result) + "\n"); |
| 84 | trace("expected = " + Hex.toString(expected) + "\n"); |
| 85 | } |
| 86 | else |
| 87 | trace(`${name}.${direction} pass\n`); |
| 88 | } |
| 89 | |
| 90 | function testBlockCipher(name, keyStr, plain, expected) |
| 91 | { |