TEA.update

Undocumented in source. Be warned that the author may not have intended to support it.

Examples

Some TEA test vectors.

__gshared immutable immutable(char)[][] test_keys = [
    "00000000000000000000000000000000",
    "00000000000000000000000000000000",
    "0123456712345678234567893456789a",
    "0123456712345678234567893456789a"
];

__gshared immutable immutable(char)[][] test_plaintexts = [
    "0000000000000000",
    "0102030405060708",
    "0000000000000000",
    "0102030405060708"
];

__gshared immutable immutable(char)[][] test_ciphertexts = [
    "41ea3a0a94baa940",
    "6a2f9cf3fccf3c55",
    "34e943b0900f5dcb",
    "773dc179878a81c0"
];


TEA t = new TEA();
foreach (uint i, string test_key; test_keys)
{
    ubyte[] buffer = new ubyte[t.blockSize];
    char[] result;
    auto key = ByteConverter.hexDecode(test_key);

    // Encryption
    t.init(true, key);
    t.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer);
    result = ByteConverter.hexEncode(buffer);
    assert(result == test_ciphertexts[i],
            t.name~": ("~result~") != ("~test_ciphertexts[i]~")");

    // Decryption
    t.init(false, key);
    t.update(ByteConverter.hexDecode(test_ciphertexts[i]), buffer);
    result = ByteConverter.hexEncode(buffer);
    assert(result == test_plaintexts[i],
            t.name~": ("~result~") != ("~test_plaintexts[i]~")");
}

Meta