]> git.proxmox.com Git - ceph.git/blob - ceph/src/crypto/isa-l/isal_crypto_accel.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / crypto / isa-l / isal_crypto_accel.cc
1 /*
2 * Ceph - scalable distributed file system
3 *
4 * Copyright (C) 2016 Mirantis, Inc.
5 *
6 * Author: Adam Kupczyk <akupczyk@mirantis.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 */
14
15 #include "crypto/isa-l/isal_crypto_accel.h"
16
17 #include "crypto/isa-l/isa-l_crypto/include/aes_cbc.h"
18
19 bool ISALCryptoAccel::cbc_encrypt(unsigned char* out, const unsigned char* in, size_t size,
20 const unsigned char (&iv)[AES_256_IVSIZE],
21 const unsigned char (&key)[AES_256_KEYSIZE])
22 {
23 if ((size % AES_256_IVSIZE) != 0) {
24 return false;
25 }
26 alignas(16) struct cbc_key_data keys_blk;
27 aes_cbc_precomp(const_cast<unsigned char*>(&key[0]), AES_256_KEYSIZE, &keys_blk);
28 aes_cbc_enc_256(const_cast<unsigned char*>(in),
29 const_cast<unsigned char*>(&iv[0]), keys_blk.enc_keys, out, size);
30 return true;
31 }
32 bool ISALCryptoAccel::cbc_decrypt(unsigned char* out, const unsigned char* in, size_t size,
33 const unsigned char (&iv)[AES_256_IVSIZE],
34 const unsigned char (&key)[AES_256_KEYSIZE])
35 {
36 if ((size % AES_256_IVSIZE) != 0) {
37 return false;
38 }
39 alignas(16) struct cbc_key_data keys_blk;
40 aes_cbc_precomp(const_cast<unsigned char*>(&key[0]), AES_256_KEYSIZE, &keys_blk);
41 aes_cbc_dec_256(const_cast<unsigned char*>(in), const_cast<unsigned char*>(&iv[0]), keys_blk.dec_keys, out, size);
42 return true;
43 }