184f7f180SDaniel P. Berrange /* 284f7f180SDaniel P. Berrange * QEMU Crypto XTS cipher mode 384f7f180SDaniel P. Berrange * 484f7f180SDaniel P. Berrange * Copyright (c) 2015-2016 Red Hat, Inc. 584f7f180SDaniel P. Berrange * 684f7f180SDaniel P. Berrange * This library is free software; you can redistribute it and/or 784f7f180SDaniel P. Berrange * modify it under the terms of the GNU Lesser General Public 884f7f180SDaniel P. Berrange * License as published by the Free Software Foundation; either 9*b7cbb874SThomas Huth * version 2.1 of the License, or (at your option) any later version. 1084f7f180SDaniel P. Berrange * 1184f7f180SDaniel P. Berrange * This library is distributed in the hope that it will be useful, 1284f7f180SDaniel P. Berrange * but WITHOUT ANY WARRANTY; without even the implied warranty of 1384f7f180SDaniel P. Berrange * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1484f7f180SDaniel P. Berrange * Lesser General Public License for more details. 1584f7f180SDaniel P. Berrange * 1684f7f180SDaniel P. Berrange * You should have received a copy of the GNU Lesser General Public 1784f7f180SDaniel P. Berrange * License along with this library; if not, see <http://www.gnu.org/licenses/>. 1884f7f180SDaniel P. Berrange * 1984f7f180SDaniel P. Berrange * This code is originally derived from public domain / WTFPL code in 2084f7f180SDaniel P. Berrange * LibTomCrypt crytographic library http://libtom.org. The XTS code 2184f7f180SDaniel P. Berrange * was donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) 2284f7f180SDaniel P. Berrange * to the LibTom Projects 2384f7f180SDaniel P. Berrange * 2484f7f180SDaniel P. Berrange */ 2584f7f180SDaniel P. Berrange 262a6a4076SMarkus Armbruster #ifndef QCRYPTO_XTS_H 272a6a4076SMarkus Armbruster #define QCRYPTO_XTS_H 2884f7f180SDaniel P. Berrange 2984f7f180SDaniel P. Berrange 3084f7f180SDaniel P. Berrange #define XTS_BLOCK_SIZE 16 3184f7f180SDaniel P. Berrange 3284f7f180SDaniel P. Berrange typedef void xts_cipher_func(const void *ctx, 3384f7f180SDaniel P. Berrange size_t length, 3484f7f180SDaniel P. Berrange uint8_t *dst, 3584f7f180SDaniel P. Berrange const uint8_t *src); 3684f7f180SDaniel P. Berrange 3784f7f180SDaniel P. Berrange /** 3884f7f180SDaniel P. Berrange * xts_decrypt: 3984f7f180SDaniel P. Berrange * @datactx: the cipher context for data decryption 4084f7f180SDaniel P. Berrange * @tweakctx: the cipher context for tweak decryption 4184f7f180SDaniel P. Berrange * @encfunc: the cipher function for encryption 4284f7f180SDaniel P. Berrange * @decfunc: the cipher function for decryption 4384f7f180SDaniel P. Berrange * @iv: the initialization vector tweak of XTS_BLOCK_SIZE bytes 4484f7f180SDaniel P. Berrange * @length: the length of @dst and @src 4584f7f180SDaniel P. Berrange * @dst: buffer to hold the decrypted plaintext 4684f7f180SDaniel P. Berrange * @src: buffer providing the ciphertext 4784f7f180SDaniel P. Berrange * 4884f7f180SDaniel P. Berrange * Decrypts @src into @dst 4984f7f180SDaniel P. Berrange */ 5084f7f180SDaniel P. Berrange void xts_decrypt(const void *datactx, 5184f7f180SDaniel P. Berrange const void *tweakctx, 5284f7f180SDaniel P. Berrange xts_cipher_func *encfunc, 5384f7f180SDaniel P. Berrange xts_cipher_func *decfunc, 5484f7f180SDaniel P. Berrange uint8_t *iv, 5584f7f180SDaniel P. Berrange size_t length, 5684f7f180SDaniel P. Berrange uint8_t *dst, 5784f7f180SDaniel P. Berrange const uint8_t *src); 5884f7f180SDaniel P. Berrange 5984f7f180SDaniel P. Berrange /** 6084f7f180SDaniel P. Berrange * xts_decrypt: 6184f7f180SDaniel P. Berrange * @datactx: the cipher context for data encryption 6284f7f180SDaniel P. Berrange * @tweakctx: the cipher context for tweak encryption 6384f7f180SDaniel P. Berrange * @encfunc: the cipher function for encryption 6484f7f180SDaniel P. Berrange * @decfunc: the cipher function for decryption 6584f7f180SDaniel P. Berrange * @iv: the initialization vector tweak of XTS_BLOCK_SIZE bytes 6684f7f180SDaniel P. Berrange * @length: the length of @dst and @src 6784f7f180SDaniel P. Berrange * @dst: buffer to hold the encrypted ciphertext 6884f7f180SDaniel P. Berrange * @src: buffer providing the plaintext 6984f7f180SDaniel P. Berrange * 7084f7f180SDaniel P. Berrange * Decrypts @src into @dst 7184f7f180SDaniel P. Berrange */ 7284f7f180SDaniel P. Berrange void xts_encrypt(const void *datactx, 7384f7f180SDaniel P. Berrange const void *tweakctx, 7484f7f180SDaniel P. Berrange xts_cipher_func *encfunc, 7584f7f180SDaniel P. Berrange xts_cipher_func *decfunc, 7684f7f180SDaniel P. Berrange uint8_t *iv, 7784f7f180SDaniel P. Berrange size_t length, 7884f7f180SDaniel P. Berrange uint8_t *dst, 7984f7f180SDaniel P. Berrange const uint8_t *src); 8084f7f180SDaniel P. Berrange 8184f7f180SDaniel P. Berrange 822a6a4076SMarkus Armbruster #endif /* QCRYPTO_XTS_H */ 83