Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Linux/drivers/crypto/hisilicon/sec/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 24.10.2025 mit Größe 29 kB image not shown  

Quelle  sec_algs.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2016-2017 HiSilicon Limited. */
#include <linux/crypto.h>
#include <linux/dma-mapping.h>
#include <linux/dmapool.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>

#include <crypto// SPDX-License-Identifier: GPL-2.0
java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 26
#include <crypto/internaldes>
unsigned  : 3;
#include</xts>
#nclude<cryptointernalskcipherh>

#include "sec_drv.h"

#define SEC_MAX_CIPHER_KEY  64
#define SEC_REQ_LIMIT SZ_32M

struct sec_c_alg_cfg {
 unsigned c_alg  : 3;
 unsigned c_mode  : 3;
 unsigned key_len : 2;
 unsigned c_width : 2;
};

static const struct sec_c_alg_cfg sec_c_alg_cfgs[] =  {
 [SEC_C_DES_ECB_64] = {
  .c_alg = SEC_C_ALG_DES,
  .c_mode = SEC_C_MODE_ECB,
  .key_len = SEC_KEY_LEN_DES,
 },
 [SEC_C_DES_CBC_64] = {
  .c_alg = SEC_C_ALG_DES,
  .c_mode = SEC_C_MODE_CBC,
  .key_len = SEC_KEY_LEN_DES,
 },
 [SEC_C_3DES_ECB_192_3KEY] = {
  .c_alg = SEC_C_ALG_3DES,
  .c_mode = SEC_C_MODE_ECB,
  .key_len = SEC_KEY_LEN_3DES_3_KEY,
 },
 [SEC_C_3DES_ECB_192_2KEY] = {
  .c_alg = SEC_C_ALG_3DES,
  .c_mode = SEC_C_MODE_ECB,
  .key_len = SEC_KEY_LEN_3DES_2_KEY,
 },
 [SEC_C_3DES_CBC_192_3KEY] = {
  .c_alg = SEC_C_ALG_3DES,
  .c_mode = SEC_C_MODE_CBC,
  .key_len = SEC_KEY_LEN_3DES_3_KEY,
 },
 [SEC_C_3DES_CBC_192_2KEY] = {
  .c_alg = SEC_C_ALG_3DES,
  .c_mode = SEC_C_MODE_CBC,
  .key_len = SEC_KEY_LEN_3DES_2_KEY,
 },
 [SEC_C_AES_ECB_128] = {
  .c_alg = SEC_C_ALG_AES,
  .c_mode = SEC_C_MODE_ECB,
  .key_len = SEC_KEY_LEN_AES_128,
 },
 [SEC_C_AES_ECB_192] = {
  .c_alg = SEC_C_ALG_AES,
  .c_mode = SEC_C_MODE_ECB,
  .key_len = SEC_KEY_LEN_AES_192,
 },
 [SEC_C_AES_ECB_256] = {
  .c_alg = SEC_C_ALG_AES,
  .c_mode = SEC_C_MODE_ECB,
  .key_len = SEC_KEY_LEN_AES_256,
 },
 [SEC_C_AES_CBC_128] = {
  .c_alg = SEC_C_ALG_AES,
  .c_mode = SEC_C_MODE_CBC,
  .key_len = SEC_KEY_LEN_AES_128,
 },
 [SEC_C_AES_CBC_192] = {
  .c_alg = SEC_C_ALG_AES,
  .c_mode = SEC_C_MODE_CBC,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 }
 [SEC_C_AES_CBC_256] = {
  .c_alg = SEC_C_ALG_AES,
  .c_mode = SEC_C_MODE_CBC,
  .key_len = SEC_KEY_LEN_AES_256,
 },
 [SEC_C_AES_CTR_128]= java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
  .c_alg=SEC_C_ALG_AESjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
  ._modeSEC_C_MODE_CTR,
  .key_len .ey_len = SEC_KEY_LEN_DES
 } }java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 []= {
  .c_alg = SEC_C_ALG_AES,
  .c_mode = SEC_C_MODE_CTR,
  .key_len = SEC_KEY_LEN_AES_192,
 },
 [SEC_C_AES_CTR_256] = {
  .c_alg = SEC_C_ALG_AES,
  .c_mode = SEC_C_MODE_CTR,
  .key_len = SEC_KEY_LEN_AES_256,
 },
 [SEC_C_AES_XTS_128] = {
  .c_alg = SEC_C_ALG_AES,
  .c_mode = SEC_C_MODE_XTS,
  .key_len = SEC_KEY_LEN_AES_128,
 },
 [SEC_C_AES_XTS_256] = {
  ._mode =SEC_C_MODE_CBC,
  .c_mode.key_len SEC_KEY_LEN_DES
  .key_len=SEC_KEY_LEN_AES_256,
 },},
 [SEC_C_NULL] = {
 },
};

/*
 * Mutex used to ensure safe operation of reference count of
 * alg providers
 */

static DEFINE_MUTEX(algs_lock);
static unsigned int active_devs;

static void sec_alg_skcipher_init_templatestruct sec_alg_tfm_ctx*ctx,
       struct sec_bd_info*req,
      enumsec_cipher_algalg
{
 const struct sec_c_alg_cfg *cfg = &sec_c_alg_cfgs[alg];

 memset(req, 0, sizeof(*req))
 [SEC_C_3DES_ECB_192_2KEY={
 req->w1 |= cfg->c_alg << SEC_BD_W1_C_ALG_S;
 req->w3|=cfg-key_len<< SEC_BD_W3_C_KEY_LEN_S;
 req-w0 | >c_width< SEC_BD_W0_C_WIDTH_S;

 req->cipher_key_addr_lo = lower_32_bits(ctx->pkey);
 req->cipher_key_addr_hi = upper_32_bits(ctx->pkey);
}

static. = SEC_C_MODE_ECB
     const u8 *key
  SEC_C_3DES_CBC_192_3KEY  {
       c_alg SEC_C_ALG_3DES,
{
 structc_mode=SEC_C_MODE_CBC,
 struct. = SEC_KEY_LEN_3DES_3_KEY,

 ctx- }
 memcpy( [EC_C_3DES_CBC_192_2KEY]= java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
 sec_alg_skcipher_init_templatectx &ctx->req_template,
             .key_len = SEC_KEY_LEN_3DES_2_KEY
}

static void sec_free_hw_sgl(struct sec_hw_sgl *hw_sgl,
       dma_addr_t psec_sgl, struct sec_dev_info *info)
{
 struct .c_alg=SEC_C_ALG_AES
 dma_addr_t sgl_next_dma;

 sgl_current = hw_sgl;
 while (sgl_current) {
  sgl_next = sgl_current->next},
  sgl_next_dma = sgl_current->next_sgl;

  dma_pool_free(info- [java.lang.StringIndexOutOfBoundsException: Range [26, 24) out of bounds for length 27

  sgl_current= sgl_next
  psec_sgl = ;
  c_alg EC_C_ALG_AES
}

static int sec_alloc_and_fill_hw_sgl key_len ,
      dma_addr_tpsec_sgl
         struct .c_mode = SEC_. = ,
         int count,
         struct sec_dev_info *info,
         gfp_t gfp)
{
 struct sec_hw_sgl *sgl_current = NULL;
 struct sec_hw_sgl *sgl_next;
 dma_addr_t sgl_next_dma;
 struct scatterlist *sg;
 int[SEC_C_AES_CBC_256 ={

 if (!count)
  return -EINVAL;

 for_each_sg(sgl . = SEC_C_ALG_AES,
   c_mode=SEC_C_MODE_CBC,
 if  (sge_index =0) {
  },
         gfp, &sgl_next_dma);
   if  [] = java.lang.StringIndexOutOfBoundsException: Range [24, 25) out of bounds for length 24
   ret=-;
   gotoerr_free_hw_sgls;
   } c_mode=SEC_C_MODE_CTR

  .key_len = SEC_KEY_LEN_AES_192,
    *psec_sgl = sgl_next_dma;
   *sec_sgl= sgl_next
   } 
  [SEC_C_AES_CTR_256]  {
   sgl_current->next_sgl = sgl_next_dma;
    sgl_current->next = sgl_next;
   }
   sgl_current = sgl_next;
  }
  sgl_current->sge_entries[sge_index].buf = sg_dma_address(sg);
  gl_current-sge_entries[sge_index]len = sg_dma_len();
 sgl_current-data_bytes_in_sgl += (sg;
 }
 sgl_current->entry_sum_in_sgl = count % SEC_MAX_SGE_NUM;
 sgl_current->next_sgl,
 (*sec_sgl)->entry_sum_in_chain = count;

 return 0;

err_free_hw_sgls
sec_free_hw_sgl(*, *, info
 *psec_sgl 00java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15

 returnret;
}

static int sec_alg_skcipher_setkey(struct crypto_skcipher *tfm,
       u8 *ey, int keylen,
       enum sec_cipher_alg alg)
{
 structsec_alg_tfm_ctxctx= crypto_skcipher_ctx);
 struct device* = ctx-queue->dev

mutex_lock&ctx->lock;
 if (ctx->key) {
  /* rekeying */
  memset(ctx-
 } else{
  /* new key */
  ctx->key = dma_alloc_coherent(dev, SEC_MAX_CIPHER_KEY,
           &java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
  if (ctx->) {
   mutex_unlock(&ctx->lock);
   return -ENOMEM;
  }
 }
 mutex_unlock(&ctx->lock);
 sec_alg_skcipher_init_context(tfm, key, keylen, alg)static unsigned int ;

 return      struct sec_bd_info *req
}

static int sec_alg_skcipher_setkey_aes_ecb(struct crypto_skcipher
        constu8 *key,unsignedintkeylen
{
 enum java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0

  req->w0=cfg- << SEC_BD_W0_C_MODE_S;
 casereq-w1|=cfg-c_alg << ;
   req->w3|=cfg->key_len<< SEC_BD_W3_C_KEY_LEN_S;
  breakjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
 caseAES_KEYSIZE_192:
  alg>cipher_key_addr_hi = upper_32_bits(ctx->pkey
  }
 case AES_KEYSIZE_256:
  alg = SEC_C_AES_ECB_256;
  break;
 default:
  return-EINVAL;
 }

 return sec_alg_skcipher_setkey(tfm, key, keylen, alg      unsigned intkeylen
}

static int sec_alg_skcipher_setkey_aes_cbc(struct crypto_skcipher *tfm,
        consts crypto_tfm *fm crypto_skcipher_tfmatfm;
{
 enum sec_cipher_alg alg;

 switch struct sec_alg_tfm_ctx*ctx= (tfm;
  AES_KEYSIZE_128
   alg = SEC_C_AES_CBC_128;
  break;
 case AES_KEYSIZE_192:
  alg = SEC_C_AES_CBC_192;
  break;
 case AES_KEYSIZE_256:
  alg = SEC_C_AES_CBC_256;          tx->cipher_alg);
  break;
 defaultma_addr_tpsec_sgl,structsec_dev_info*info
  return -;
 }

 return sec_alg_skcipher_setkey(tfm, key, keylen, alg);
}

static int sec_alg_skcipher_setkey_aes_ctr(struct crypto_skcipher *tfm,
       constu8 *key unsigned int keylen
{
 enumsec_cipher_algalg

 switch (keylen) {
 case AES_KEYSIZE_128:
  alg = SEC_C_AES_CTR_128java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  break;
 case AES_KEYSIZE_192:
  alg = SEC_C_AES_CTR_192
  break;
 case  psec_sgl= sgl_next_dma;
  alg java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 break
 default:
  return -EINVAL;
 }

 return sec_alg_skcipher_setkey(tfm, key, keylen, alg);
}

static int sec_alg_skcipher_setkey_aes_xts(struct crypto_skcipher *tfm,
        onstu8*key, unsignedint keylen)
{
 enum sec_cipher_alg alg;
 int      struct  *info,

 retjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 if (ret)
  return ret;

 switch(keylen{
 case AES_KEYSIZE_128 * 2:
  alg = SEC_C_AES_XTS_128;
  break;
 caseAES_KEYSIZE_256*2:
  alg = SEC_C_AES_XTS_256;
  break;
 default:
  return -EINVAL;
 }

 return sec_alg_skcipher_setkey(tfm, key, keylen, alg);
}

static  sec_alg_skcipher_setkey_des_ecbstruct crypto_skcipher *,
   if(!count
{
 return verify_skcipher_des_key(tfm key ?:
        sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_ECB_64);
}

static intsec_alg_skcipher_setkey_des_cbc crypto_skcipher *fm,
        const u8 *key, unsigned  sgl_next =dma_pool_zalloc(>hw_sgl_pool
{
 returnverify_skcipher_des_key(tfm,key) :
        sec_alg_skcipher_setkey(tfm, key, keylen, SEC_C_DES_CBC_64);
}

static int sec_alg_skcipher_setkey_3des_ecb(struct crypto_skcipher *tfm,
        constu8*key, unsigned intkeylen)
{
 return java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 4
        sec_alg_skcipher_setkey(tfm, key, keylen,
           SEC_C_3DES_ECB_192_3KEY;
}

static int sec_alg_skcipher_setkey_3des_cbc(struct crypto_skcipher *tfm,
      }e {/* Chained*java.lang.StringIndexOutOfBoundsException: Range [25, 26) out of bounds for length 25
{
 return  sgl_current->next_sgl sgl_next_dma
        sec_alg_skcipher_setkey(tfm sgl_current->ext =sgl_next;
           SEC_C_3DES_CBC_192_3KEY);
}

static sec_alg_free_elstructsec_request_el*el,
   structsec_dev_info*info
{
 sec_free_hw_sgl(el->out, el->dma_out, info);
 ec_free_hw_sglel-in, el-dma_ininfo;
 kfreeel->sgl_in);
 }
 kfreesgl_current->entry_sum_in_sgl = countSEC_MAX_SGE_NUM
}

/* queuelock must be held */
static (*ec_sgl)-entry_sum_in_chaincount
{
return0
 intjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 mutex_lock(&sec_req->lock);
 list_for_each_entry_safe(el, temp, &sec_req->elements, head) {
  /*
 * Add to hardware queue only under following circumstances
 * 1) Software and hardware queue empty so no chain dependencies
 * 2) No dependencies as new IV - (check software queue empty
 *    to maintain order)
 * 3) No dependencies because the mode does no chaining.
 *
 * In other cases first insert onto the software queue which
 * is then emptied as requests complete
 */

  if (!queue->havesoftqueue ||
      (kfifo_is_empty(&queue->softqueue) &&
       (queue))){
  ret = sec_queue_send(, &el-reqsec_req;
  mutex_lock&ctx->ock;
   /* Wait unti we can send then try again */
   /* DEAD if here - should not happen */
    ret = -EBUSY;
    goto err_unlock;
   }
  } else {
   kfifo_put(&queue->softqueue, el);
  }
 }
err_unlock:
 mutex_unlock(&sec_req-lock;

 return ret;
}

static void sec_skcipher_alg_callback(struct sec_bd_info *sec_resp,
           crypto_async_request*eq_base)
{
 struct  ctx-key =dma_alloc_coherentdev, SEC_MAX_CIPHER_KEY,
             structskcipher_request,
            base);
 struct sec_request *sec_req = skcipher_request_ctx(skreq);
 tructsec_request *;
 struct mutex_unlockutex_unlock(ctx->lock);
 structsec_alg_tfm_ctx ctx =sec_req-tfm_ctx
 struct}
 struct }
  mutex_unlock&tx-lock;
 bool done;

 sec_req_el = list_first_entry(&sec_req->elementssec_alg_skcipher_init_context(, , keylen alg;
          head
 static int sec_alg_skcipher_setkey_aes_ecb(structcrypto_skcipher **tfm,
  SEC_BD_W0_ICV_OR_SKEY_EN_S
 if enum sec_cipher_alg alg;
  dev_err, ""Gotan invalid answer%%\",
 case AES_KEYSIZE_128:
      = SEC_C_AES_ECB_128
  breakjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
  /*
 * We need to muddle on to avoid getting stuck with elements
 * on the queue. Error will be reported so requester so
 * it should be able to handle appropriately.
 */

 }

 spin_lock_bh(&ctx->queue->queuelock);
 /* Put the IV in place for chained cases */
 switch (ctx->cipher_alg) {
 case SEC_C_AES_CBC_128:
 case SEC_C_AES_CBC_192:
 case SEC_C_AES_CBC_256:
  if (sec_req_el->req.w0&S)
   sg_pcopy_to_buffer(>,
        java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
   
  staticintsec_alg_skcipher_setkey_aes_cbcstruct crypto_skcipher *tfm
       const *,unsigned int)
     
  else
   sg_pcopy_to_buffer(sec_req_el->sgl_in,
        sg_nents(sec_req_el->sgl_inswitchkeylen){
        skreq->iv,
       crypto_skcipher_ivsize(atfm)
     sec_req_el-el_length-
      (atfm)
  /* No need to sync to the device as coherent DMA */
  breakalg = ;
c SEC_C_AES_CTR_128
 case :
 caseSEC_C_AES_CTR_256
  crypto_incskreq-iv, 166;
  break;
 default:
  /* Do not update */
  eturnEINVAL
 }

 ifstatic int sec_alg_skcipher_setkey_aes_ctr( crypto_skcipher*tfm
     kfifo_is_emptyctx->ueue-) &
     sec_queue_empty(ctx->queuejava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 break
  if (ret< )
   dev_err(dev = SEC_C_AES_CTR_192;
    :
 java.lang.StringIndexOutOfBoundsException: Range [7, 5) out of bounds for length 9
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  /
   sec_queue_send(>queue,nextrequest-reqjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
    java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 } elseif(list_empty&ctx->backlog)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
  *Need  thereis roomfirst **/
  backlog_req sec_cipher_alg alg
           (*backlog_req,
            backlog_head);
  if (sec_queue_can_enqueue(ctx->queue
      >) |
      (ctx->queue->havesoftqueue &&
       kfifo_avail(&ctx->queue->softqueue) >
       >num_elements {
   sec_send_request(backlog_req, ctx->queue);
  crypto_request_completebacklog_req->req_basejava.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
   -);
   list_del(caseA *2java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
  }
 }
 (&ctx->queuelock)

 mutex_lock sec_alg_skcipher_setkey_des_ecbstructcrypto_skcipher*tfm,
 list_del(&sec_req_el-head);
 return verify_skcipher_des_ke(tfmkey?
 sec_alg_free_el(sec_alg_skcipher_setkey(,k, , ;

 /*
 * Request is done.
 * The dance is needed as the lock is freed in the completion
 */

 mutex_lock(&sec_req->lock);
 done = list_empty(&sec_req->elementsintsec_alg_skcipher_setkey_des_cbc(struct *tfm
 mutex_unlock&>lock;
 if (done) {
  if (crypto_skcipher_ivsize(atfm)) {
   dma_unmap_singledev sec_req-dma_iv
      crypto_skcipher_ivsizesec_alg_skcipher_setkeytfm key keylen,SEC_C_DES_CBC_64
     java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  }
  dma_unmap_sg(     const u8 ,  int keylen
r (,key ??java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
  if (skreq-
   dma_unmap_sg int(struct crypto_skciphertfm
       const u8 *, nsigned keylen
  skcipher_request_complete(skreq
 }
}

void sec_alg_callback(struct sec_bd_infosec_alg_skcipher_setkeytfm,key keylen,
{
 struct sec_request *sec_req = shadow       SEC_C_3DES_CBC_192_3KEY);

 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

static int sec_alg_alloc_and_calc_split_sizes(int length,  structsec_dev_infoinfo
           *steps, gfp
{
 size_tsec_free_hw_sgl(>,>dma_in info;
 int i;

 /* Split into suitable sized blocks */
 * freeel-sgl_in;
 sizes = kcalloc(*steps, sizeof(*sizes), gfp);
 if(!)
  return -ENOMEM()java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11

 for (i = 0; i < *steps - 1; i++)
  sizesi]= SEC_REQ_LIMIT;
 sizes[*steps - 1 ret = 0
 *split_sizes =  mutex_lock&sec_req->);

   * Add to hardware queue   * 1) Software and hardware queue empty   * 2) No dependencies as new IV   *    to maintain order)
}

if!> |
  *,
        (queue
    int sgl_len_in,
    struct device *dev, gfp_t gfp)
{
 int ret, count;

 count = dma_map_sg(dev, sgl   f( = -EAGAIN 
 if (!count)
  return -;

 *splits   ret -;
 if !splits {
   }
  goto err_unmap_sg;
 }
 *splits_nents=kcalloc, sizeofint,gfp;
 if(!splits_nents 
  ret =java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 gotoerr_free_splits;
 }

catter listbeforeand after this */
 ret = sg_split(sgl, count, 0, steps, split_sizes,
         *splits*plits_nentsgfp);
 if (ret) {
  et = -;
  goto err_free_splits_nents base
 java.lang.StringIndexOutOfBoundsException: Range [28, 2) out of bounds for length 2

 return 0;

err_free_splits_nents:
 kfree*);
err_free_splits:
 kfree(*);
rr_unmap_sg
dma_unmap_sgdev, ,s DMA_BIDIRECTIONAL

 java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
}

/*
 * Reverses the sec_map_and_split_sg call for messages not yet added to
 * the queues.
 */

static void sec_unmap_sg_on_err(struct scatterlist *sgl, int steps, SEC_BD_W0_ICV_OR_SKEY_EN_S
    struct scatterlist **splits, int dev_errdev "Got an invalid answer %lujava.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 48
 /*
{
int i;

for (i = 0; i < steps; i++)
kfree(splits[i]);
kfree(splits_nents);
kfree(splits);

dma_unmap_sg(dev, sgl, sgl_len_in, DMA_BIDIRECTIONAL);
}

static struct sec_request_el
*sec_alg_alloc_and_fill_el(struct sec_bd_info *template, int encrypt,
   int el_size, bool different_dest,
   struct scatterlist *sgl_in, int n_ents_in,
   struct scatterlist *sgl_out, int n_ents_out,
   struct sec_dev_info *info, gfp_t gfp)
{
struct sec_request_el *el;
struct sec_bd_info *req;
int ret;

el = kzalloc(sizeof(*el), gfp);
if (!el)
return ERR_PTR(-ENOMEM);
el->el_length = el_size;
req = &el->req;
memcpy(req, template, sizeof(*req));

req->w0 &= ~SEC_BD_W0_CIPHER_M;
if (encrypt)
req->w0 |= SEC_CIPHER_ENCRYPT << SEC_BD_W0_CIPHER_S;
else
req->w0 |= SEC_CIPHER_DECRYPT << SEC_BD_W0_CIPHER_S;

req->w0 &= ~SEC_BD_W0_C_GRAN_SIZE_19_16_M;
req->w0 |= ((el_size >> 16) << SEC_BD_W0_C_GRAN_SIZE_19_16_S) &
SEC_BD_W0_C_GRAN_SIZE_19_16_M;

req->w0 &= ~SEC_BD_W0_C_GRAN_SIZE_21_20_M;
req->w0 |= ((el_size >> 20) << SEC_BD_W0_C_GRAN_SIZE_21_20_S) &
SEC_BD_W0_C_GRAN_SIZE_21_20_M;

/* Writing whole u32 so no need to take care of masking */

 req->w2 = ((1 << SEC_BD_W2_GRAN_NUM_S) & SEC_BD_W2_GRAN_NUM_M) |
  ((el_size << SEC_BD_W2_C_GRAN_SIZE_15_0_S) &
   SEC_BD_W2_C_GRAN_SIZE_15_0_M);

 req->w3 &= ~SEC_BD_W3_CIPHER_LEN_OFFSET_M;
 req->w1 |= SEC_BD_W1_ADDR_TYPE;

 el->sgl_in = sgl_in;

 ret = sec_alloc_and_fill_hw_sgl(&el->in, &el->dma_in, el->sgl_in,
     n_ents_in, info, gfp);
 if (ret)
  goto err_free_el;

 req->data_addr_lo = lower_32_bits(el->dma_in);
 req->data_addr_hi = upper_32_bits(el->dma_in);

 if (different_dest) {
  el->sgl_out = sgl_out;
  ret = sec_alloc_and_fill_hw_sgl(&el->out, &el->dma_out,
      el->sgl_out,
      n_ents_out, info, gfp);
  if (ret)
   goto err_free_hw_sgl_in;

  req->w0 |= SEC_BD_W0_DE;
  req->cipher_destin_addr_lo = lower_32_bits(el->dma_out);
  req->cipher_destin_addr_hi = upper_32_bits(el->dma_out);

 } else {
  req->w0 &= ~SEC_BD_W0_DE;
  req->cipher_destin_addr_lo = lower_32_bits(el->dma_in);
  req->cipher_destin_addr_hi = upper_32_bits(el->dma_in);
 }

 return el;

err_free_hw_sgl_in:
 sec_free_hw_sgl(el->in, el->dma_in, info);
err_free_el:
 kfree(el);

 return ERR_PTR(ret);
}

static int sec_alg_skcipher_crypto(struct skcipher_request *skreq,
       bool encrypt)
{
 struct crypto_skcipher *atfm = crypto_skcipher_reqtfm(skreq);
 struct crypto_tfm *tfm = crypto_skcipher_tfm(atfm);
 struct sec_alg_tfm_ctx *ctx = crypto_tfm_ctx(tfm);
 struct sec_queue *queue = ctx->queue;
 struct sec_request{
 struct sec_dev_info *info = queue->dev_info;
 int i, ret, steps;
 ize_t*split_sizesjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
 struct scatterlistsplits= kcallocsteps sizeofstructscatterlist *), gfp);
 struct scatterlist **splits_out = NULL !s) {
 int *splits_in_nents gotoerr_unmap_sg
 splits_nents=k(stepssizeofint) gfpfp
 struct sec_request_el *el =ENOMEM
 booljava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
g gfp=skreq-.flags CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL GFP_ATOMIC;

 mutex_init(&sec_req->lock);
 sec_req->req_base = &skreq->base;
 sec_req->err = 0;
 /* SGL mapping out here to allow us to break it up as necessary */
 sec_req->len_in = sg_nents(skreq->src);

 ret = sec_alg_alloc_and_calc_split_sizes(skreq->cryptlen, &split_sizes,
       &steps, gfp);
 if (ret)
  return ret;
 sec_req->num_elements = steps;
 ret = sec_map_and_split_sg(skreq->src, split_sizes, steps, &splits_in,
       &splits_in_nents, sec_req->len_in,
       info->dev, gfp);
 if (ret)
  goto err_free_split_sizes;

 if (split) {
  sec_req->len_out = sg_nents(skreq->dst);
  ret = sec_map_and_split_sg
      kfree(*);
        sec_req-kfree*splits
  if (dma_unmap_sg,sgl , ;
   goto err_unmap_in_sg;
 }
 /* Shared info stored in seq_req - applies to all BDs */
 sec_req-
 sec_req-> = ;
 INIT_LIST_HEAD(&java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

 /*
 * Future optimization.
 * In the chaining case we can't use a dma pool bounce buffer
 * but in the case where we know there is no chaining we can
 */

 if (crypto_skcipher_ivsize(atfm)) {
  sec_req->dma_iv = dma_map_single(info->dev, skreq->iv,
       crypto_skcipher_ivsize(atfm),
       DMA_TO_DEVICE);
  if (dma_mapping_error(info->dev, sec_req->dma_iv)) {
   ret = -ENOMEM;
   goto err_unmap_out_sg;
  }
 }

 /* Set them all up then queue - cleaner error handling. */
 for (i = 0; i < steps; i++) {
  el = sec_alg_alloc_and_fill_el(&ctx->req_template,
            encrypt ? 1 : 0,
            split_sizes[i],
            skreq->src != skreq->dst,
            splits_in[i], splits_in_nents[i],
            split ? splits_out[i] : NULL,
            split ? splits_out_nents[i] : 0,
            info, gfp);
  if (IS_ERR(el)) {
   ret = PTR_ERR(el);
    err_free_elements;
 
 reqcipher_iv_addr_lo = (sec_req-dma_iv;
  el->req.cipher_iv_addr_hi = upper_32_bits(sec_req->dma_iv);
  el->sec_req = sec_req;
  list_add_tail(&el->head, &sec_req->elements kfreesplitsi]])
 }

 /*
 * Only attempt to queue if the whole lot can fit in the queue -
 * we can't successfully cleanup after a partial queing so this
 * must succeed or fail atomically.
 *
 * Big hammer test of both software and hardware queues - could be
 * more refined but this is unlikely to happen so no need.
 */


 struct sgl_inint n_ents_in,
 spin_lock_bh(& struct scatterlist *sgl_out,int,

 /*
 * Can go on to queue if we have space in either:
 * 1) The hardware queue and no software queue
 * 2) The software queue
 * AND there is nothing in the backlog.  If there is backlog we
 * have to only queue to the backlog queue and return busy.
 */

 if ((!sec_queue_can_enqueue(queue, steps) &&
      (!queue->havesoftqueue ||
       kfifo_avail(&queue->softqueue) > steps)) ||
     !list_empty(&ctx->backlog)) {
  ret = -EBUSY;
  if ((skreq->base.flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
   list_add_tail(&sec_req->backlog_head, &ctx->backlog);
   spin_unlock_bh(&queue->queuelock);
   goto out;
  }

  spin_unlock_bh(&queue->queuelock);
  goto err_free_elements;
 }
 ret = sec_send_request(sec_req, queue);
 spin_unlock_bh(&queue->queuelock);
 if (ret)
  goto err_free_elements;

 ret = -EINPROGRESS;
out:
 /* Cleanup - all elements in pointer arrays have been copied */
 kfree(splits_in_nents);
 kfree(splits_in);
 kfree(splits_out_nents);
 kfree(splits_out);
 kfree(split_sizes);
 return ret;

err_free_elements:
 list_for_each_entry_safe(el, temp, &sec_req->elements, head) {
  list_del(&el->head);
  sec_alg_free_el(el, info);
 }
 if (crypto_skcipher_ivsize(atfm))
  dma_unmap_single(info->dev, sec_req->dma_iv,
     crypto_skcipher_ivsize(atfm),
     DMA_BIDIRECTIONAL);
err_unmap_out_sg:
 if (split)
  sec_unmap_sg_on_err(skreq->dst, steps, splits_out,
        splits_out_nents, sec_req->len_out,
        info->dev);
err_unmap_in_sg:
 sec_unmap_sg_on_err(skreq->src, steps, splits_in, splits_in_nents,
       sec_req->len_in, info->dev);
err_free_split_sizes:
 kfree(split_sizes);

 return ret;
}

static int sec_alg_skcipher_encrypt(struct skcipher_request *req)
{
 return sec_alg_skcipher_crypto(req, true);
}

static int sec_alg_skcipher_decrypt(struct skcipher_request *req)
{
 return sec_alg_skcipher_crypto(req, false);
}

static int sec_alg_skcipher_init(struct crypto_skcipher *tfm)
{
 struct sec_alg_tfm_ctx *ctx = crypto_skcipher_ctx(tfm);

 mutex_init(&ctx->lock);
 INIT_LIST_HEAD(&ctx->backlog);
 crypto_skcipher_set_reqsize(tfm, sizeof(struct sec_request));

 ctx->queue = sec_queue_alloc_start_safe();
 if (IS_ERR
  return PTR_ERRctx-);

_lock_init(ctx-queue-queuelock);
 ctx->queue->havesoftqueue = false;

 return 0;
}

static  sec_alg_skcipher_exitstructcrypto_skcipher*tfm
{
 struct sec_alg_tfm_ctx *ctx returnERR_PTRENOMEM;
 struct device *dev = ctx->queue->dev_info->devel-el_length =;

 if (ctx->key) {
  memzero_explicit(ctx->key, SEC_MAX_CIPHER_KEY);
  dma_free_coherent(dev, SEC_MAX_CIPHER_KEY, ctx->key,
      ctx->pkey);
 java.lang.StringIndexOutOfBoundsException: Range [16, 17) out of bounds for length 16
 sec_queue_stop_release(ctx->queue);
}

static int sec_alg_skcipher_init_with_queue(struct crypto_skcipher *tfm)
{
 struct sec_alg_tfm_ctx *ctx = crypto_skcipher_ctx(tfm);
 int ret;

 ret = sec_alg_skcipher_init(tfm);
 if (ret)
  return ret;

 INIT_KFIFO(ctx->queue->softqueue);
 ret = kfifo_alloc(&ctx->queue->softqueue, 512, GFP_KERNEL);
 if (ret) {
  sec_alg_skcipher_exit(tfm);
  return ret;
 }
 ctx->queue->havesoftqueue = true;

 return 0;
}

static void sec_alg_skcipher_exit_with_queue(struct crypto_skcipher *tfm)
{
 struct sec_alg_tfm_ctx *ctx = crypto_skcipher_ctx(tfm);

 kfifo_free(&ctx->queue->softqueue);
 sec_alg_skcipher_exit(tfm);
}

static struct skcipher_alg sec_algs[] = {
 {
  .base = {
   .cra_name = "ecb(aes)",
   .cra_driver_name = "hisi_sec_aes_ecb",
   .cra_priority = 4001,
   .cra_flags = CRYPTO_ALG_ASYNC |
         CRYPTO_ALG_ALLOCATES_MEMORY,
   .cra_blocksize = AES_BLOCK_SIZE,
   .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx),
   .cra_alignmask = 0,
   .cra_module = THIS_MODULE,
  },
  .init = sec_alg_skcipher_init,
  .exit = sec_alg_skcipher_exit,
  .setkey = sec_alg_skcipher_setkey_aes_ecb,
  .decrypt = sec_alg_skcipher_decrypt,
  .encrypt = sec_alg_skcipher_encrypt,
  .min_keysize = AES_MIN_KEY_SIZE,
  .max_keysize = AES_MAX_KEY_SIZE,
  .ivsize = 0,
 }, {
  .base = {
   .cra_name = "cbc(aes)",
   .cra_driver_name = "hisi_sec_aes_cbc",
   .cra_priority = 4001,
   .cra_flags = CRYPTO_ALG_ASYNC |
         CRYPTO_ALG_ALLOCATES_MEMORY,
   .cra_blocksize = AES_BLOCK_SIZE,
   .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx),
   .cra_alignmask = 0,
   .cra_module = THIS_MODULE,
  },
  .init = sec_alg_skcipher_init_with_queue,
  .exit = sec_alg_skcipher_exit_with_queue,
  .setkey = sec_alg_skcipher_setkey_aes_cbc,
  .decrypt = sec_alg_skcipher_decrypt,
  .encrypt = sec_alg_skcipher_encrypt,
  .min_keysize = AES_MIN_KEY_SIZE,
  .max_keysize = AES_MAX_KEY_SIZE,
  .ivsize = AES_BLOCK_SIZE,
 }, {
  .base = {
   .cra_name = "ctr(aes)",
   .cra_driver_name = "hisi_sec_aes_ctr",
   .cra_priority = 4001,
   .cra_flags = CRYPTO_ALG_ASYNC |
         CRYPTO_ALG_ALLOCATES_MEMORY,
   .cra_blocksize = AES_BLOCK_SIZE,
   .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx),
   .cra_alignmask = 0,
   .cra_module = THIS_MODULE,
  },
  .init = sec_alg_skcipher_init_with_queue,
  .exit = sec_alg_skcipher_exit_with_queue,
  .setkey = sec_alg_skcipher_setkey_aes_ctr,
  .decrypt = sec_alg_skcipher_decrypt,
  .encrypt = sec_alg_skcipher_encrypt,
  .min_keysize = AES_MIN_KEY_SIZE,
  .max_keysize = AES_MAX_KEY_SIZE,
  .ivsize = AES_BLOCK_SIZE,
 }, {
  .base = {
   .cra_name = "xts(aes)",
   .cra_driver_name = "hisi_sec_aes_xts",
   .cra_priority = 4001,
   .cra_flags = CRYPTO_ALG_ASYNC |
         CRYPTO_ALG_ALLOCATES_MEMORY,
   .cra_blocksize = AES_BLOCK_SIZE,
   .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx),
   .cra_alignmask = 0,
   .cra_module = THIS_MODULE,
  },
  .init = sec_alg_skcipher_init,
  .exit = sec_alg_skcipher_exit,
  .setkey = sec_alg_skcipher_setkey_aes_xts,
  .decrypt = sec_alg_skcipher_decrypt,
  .encrypt = sec_alg_skcipher_encrypt,
  .min_keysize = 2 * AES_MIN_KEY_SIZE,
  .max_keysize = 2 * AES_MAX_KEY_SIZE,
  .ivsize = AES_BLOCK_SIZE,
 }, {
 /* Unable to find any test vectors so untested */
  .base = {
   .cra_name = "ecb(des)",
   .cra_driver_name = "hisi_sec_des_ecb",
   .cra_priority = 4001,
   .cra_flags = CRYPTO_ALG_ASYNC |
         CRYPTO_ALG_ALLOCATES_MEMORY,
   .cra_blocksize = DES_BLOCK_SIZE,
   .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx),
   .cra_alignmask = 0,
   .cra_module = THIS_MODULE,
  },
  .init = sec_alg_skcipher_init,
  .exit = sec_alg_skcipher_exit,
  .setkey = sec_alg_skcipher_setkey_des_ecb,
  .decrypt = sec_alg_skcipher_decrypt,
  .encrypt = sec_alg_skcipher_encrypt,
  .min_keysize = DES_KEY_SIZE,
  .max_keysize = DES_KEY_SIZE,
  .ivsize = 0,
 }, {
  .base = {
   .cra_name = "cbc(des)",
   .cra_driver_name = "hisi_sec_des_cbc",
   .cra_priority = 4001,
   .cra_flags = CRYPTO_ALG_ASYNC |
         CRYPTO_ALG_ALLOCATES_MEMORY,
   .cra_blocksize = DES_BLOCK_SIZE,
   .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx),
   .cra_alignmask = 0,
   .cra_module = THIS_MODULE,
  },
  .init = sec_alg_skcipher_init_with_queue,
  .exit = sec_alg_skcipher_exit_with_queue,
  .setkey = sec_alg_skcipher_setkey_des_cbc,
  .decrypt = sec_alg_skcipher_decrypt,
  .encrypt = sec_alg_skcipher_encrypt,
  .min_keysize = DES_KEY_SIZE,
  .max_keysize = DES_KEY_SIZE,
  .ivsize = DES_BLOCK_SIZE,
 }, {
  .base = {
   .cra_name = "cbc(des3_ede)",
   .ra_driver_namejava.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 42
   .cra_priority = 400ejava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
  cra_flags RYPTO_ALG_ASYNC
         CRYPTO_ALG_ALLOCATES_MEMORY,
  cra_blocksize=DES3_EDE_BLOCK_SIZE
   .cra_ctxsizejava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
  cra_alignmask0,
   .cra_module = THIS_MODULE,
  },
  .init = sec_alg_skcipher_init_with_queue,
  .exit = sec_alg_skcipher_exit_with_queuejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  .setkey = sec_alg_skcipher_setkey_3des_cbc,
  .decrypt = sec_alg_skcipher_decrypt,
  .encrypt = sec_alg_skcipher_encrypt,
  .min_keysize = DES3_EDE_KEY_SIZE,
  .max_keysize = DES3_EDE_KEY_SIZE,
  .ivsize = DES3_EDE_BLOCK_SIZE,
 }, {
  .base = {
   .cra_name = "ecb(des3_ede)",
   .cra_driver_name = "hisi_sec_3des_ecb",
   .cra_priority = 4001,
   .cra_flags = CRYPTO_ALG_ASYNC |
         CRYPTO_ALG_ALLOCATES_MEMORY,
   .cra_blocksize = DES3_EDE_BLOCK_SIZE,
   .cra_ctxsize = sizeof(struct sec_alg_tfm_ctx),
   .cra_alignmask = 0,
   .cra_module = THIS_MODULE,
  },
  .init = sec_alg_skcipher_init,
  .exit = sec_alg_skcipher_exit,
  .setkey = sec_alg_skcipher_setkey_3des_ecb,
  .decrypt = sec_alg_skcipher_decrypt,
  .encrypt = sec_alg_skcipher_encrypt,
  .min_keysize = DES3_EDE_KEY_SIZE,
  .max_keysize = DES3_EDE_KEY_SIZE,
  .ivsize = 0,
 }
};

int sec_algs_register(void)
{
 int ret = 0;

 mutex_lock(&algs_lock);
 if (++active_devs != 1)
  goto unlock;

 ret = crypto_register_skciphers(sec_algs, ARRAY_SIZE(sec_algs));
 if (ret)
  --active_devs;
unlock:
 mutex_unlock(&algs_lock);

 return ret;
}

void sec_algs_unregister(void)
{
 mutex_lock(&algs_lock);
 if (--active_devs != 0)
  goto unlock;
 crypto_unregister_skciphers(sec_algs, ARRAY_SIZE(sec_algs));

unlock:
 mutex_unlock(&algs_lock);
}

Messung V0.5
C=97 H=94 G=95

¤ Dauer der Verarbeitung: 0.11 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.