1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2001-2021 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci/*- 11e1051a39Sopenharmony_ci * Fujitsu SPARC64 X support for camellia modes. 12e1051a39Sopenharmony_ci * This file is included by cipher_camellia_hw.c 13e1051a39Sopenharmony_ci */ 14e1051a39Sopenharmony_ci 15e1051a39Sopenharmony_cistatic int cipher_hw_camellia_t4_initkey(PROV_CIPHER_CTX *dat, 16e1051a39Sopenharmony_ci const unsigned char *key, 17e1051a39Sopenharmony_ci size_t keylen) 18e1051a39Sopenharmony_ci{ 19e1051a39Sopenharmony_ci int ret = 0, bits, mode = dat->mode; 20e1051a39Sopenharmony_ci PROV_CAMELLIA_CTX *adat = (PROV_CAMELLIA_CTX *)dat; 21e1051a39Sopenharmony_ci CAMELLIA_KEY *ks = &adat->ks.ks; 22e1051a39Sopenharmony_ci 23e1051a39Sopenharmony_ci dat->ks = ks; 24e1051a39Sopenharmony_ci bits = keylen * 8; 25e1051a39Sopenharmony_ci 26e1051a39Sopenharmony_ci cmll_t4_set_key(key, bits, ks); 27e1051a39Sopenharmony_ci 28e1051a39Sopenharmony_ci if (dat->enc || (mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE)) { 29e1051a39Sopenharmony_ci dat->block = (block128_f) cmll_t4_encrypt; 30e1051a39Sopenharmony_ci switch (bits) { 31e1051a39Sopenharmony_ci case 128: 32e1051a39Sopenharmony_ci if (mode == EVP_CIPH_CBC_MODE) 33e1051a39Sopenharmony_ci dat->stream.cbc = (cbc128_f) cmll128_t4_cbc_encrypt; 34e1051a39Sopenharmony_ci else if (mode == EVP_CIPH_CTR_MODE) 35e1051a39Sopenharmony_ci dat->stream.ctr = (ctr128_f) cmll128_t4_ctr32_encrypt; 36e1051a39Sopenharmony_ci else 37e1051a39Sopenharmony_ci dat->stream.cbc = NULL; 38e1051a39Sopenharmony_ci break; 39e1051a39Sopenharmony_ci case 192: 40e1051a39Sopenharmony_ci case 256: 41e1051a39Sopenharmony_ci if (mode == EVP_CIPH_CBC_MODE) 42e1051a39Sopenharmony_ci dat->stream.cbc = (cbc128_f) cmll256_t4_cbc_encrypt; 43e1051a39Sopenharmony_ci else if (mode == EVP_CIPH_CTR_MODE) 44e1051a39Sopenharmony_ci dat->stream.ctr = (ctr128_f) cmll256_t4_ctr32_encrypt; 45e1051a39Sopenharmony_ci else 46e1051a39Sopenharmony_ci dat->stream.cbc = NULL; 47e1051a39Sopenharmony_ci break; 48e1051a39Sopenharmony_ci default: 49e1051a39Sopenharmony_ci ret = -1; 50e1051a39Sopenharmony_ci break; 51e1051a39Sopenharmony_ci } 52e1051a39Sopenharmony_ci } else { 53e1051a39Sopenharmony_ci dat->block = (block128_f) cmll_t4_decrypt; 54e1051a39Sopenharmony_ci switch (bits) { 55e1051a39Sopenharmony_ci case 128: 56e1051a39Sopenharmony_ci dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ? 57e1051a39Sopenharmony_ci (cbc128_f) cmll128_t4_cbc_decrypt : NULL; 58e1051a39Sopenharmony_ci break; 59e1051a39Sopenharmony_ci case 192: 60e1051a39Sopenharmony_ci case 256: 61e1051a39Sopenharmony_ci dat->stream.cbc = mode == EVP_CIPH_CBC_MODE ? 62e1051a39Sopenharmony_ci (cbc128_f) cmll256_t4_cbc_decrypt : NULL; 63e1051a39Sopenharmony_ci break; 64e1051a39Sopenharmony_ci default: 65e1051a39Sopenharmony_ci ret = -1; 66e1051a39Sopenharmony_ci break; 67e1051a39Sopenharmony_ci } 68e1051a39Sopenharmony_ci } 69e1051a39Sopenharmony_ci if (ret < 0) { 70e1051a39Sopenharmony_ci ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SETUP_FAILED); 71e1051a39Sopenharmony_ci return 0; 72e1051a39Sopenharmony_ci } 73e1051a39Sopenharmony_ci return 1; 74e1051a39Sopenharmony_ci} 75e1051a39Sopenharmony_ci 76e1051a39Sopenharmony_ci#define PROV_CIPHER_HW_declare(mode) \ 77e1051a39Sopenharmony_cistatic const PROV_CIPHER_HW t4_camellia_##mode = { \ 78e1051a39Sopenharmony_ci cipher_hw_camellia_t4_initkey, \ 79e1051a39Sopenharmony_ci ossl_cipher_hw_generic_##mode, \ 80e1051a39Sopenharmony_ci cipher_hw_camellia_copyctx \ 81e1051a39Sopenharmony_ci}; 82e1051a39Sopenharmony_ci#define PROV_CIPHER_HW_select(mode) \ 83e1051a39Sopenharmony_ciif (SPARC_CMLL_CAPABLE) \ 84e1051a39Sopenharmony_ci return &t4_camellia_##mode; 85