Skip to content
Snippets Groups Projects
Select Git revision
  • v3.12-rc6
  • master default protected
  • objtool-32bit
  • objtool
  • v5.9
  • v5.9-rc8
  • v5.9-rc7
  • v5.9-rc6
  • v5.9-rc5
  • v5.9-rc4
  • v5.9-rc3
  • v5.9-rc2
  • v5.9-rc1
  • v5.8
  • v5.8-rc7
  • v5.8-rc6
  • v5.8-rc5
  • v5.8-rc4
  • v5.8-rc3
  • v5.8-rc2
  • v5.8-rc1
  • v5.7
  • v5.7-rc7
  • v5.7-rc6
24 results

seqiv.c

Blame
  • Forked from Jonas Rabenstein / Linux
    Source project has a limited visibility.
    seqiv.c 8.53 KiB
    /*
     * seqiv: Sequence Number IV Generator
     *
     * This generator generates an IV based on a sequence number by xoring it
     * with a salt.  This algorithm is mainly useful for CTR and similar modes.
     *
     * Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
     *
     * This program is free software; you can redistribute it and/or modify it
     * under the terms of the GNU General Public License as published by the Free
     * Software Foundation; either version 2 of the License, or (at your option)
     * any later version.
     *
     */
    
    #include <crypto/internal/aead.h>
    #include <crypto/internal/skcipher.h>
    #include <crypto/rng.h>
    #include <linux/err.h>
    #include <linux/init.h>
    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/slab.h>
    #include <linux/spinlock.h>
    #include <linux/string.h>
    
    struct seqiv_ctx {
    	spinlock_t lock;
    	u8 salt[] __attribute__ ((aligned(__alignof__(u32))));
    };
    
    static void seqiv_complete2(struct skcipher_givcrypt_request *req, int err)
    {
    	struct ablkcipher_request *subreq = skcipher_givcrypt_reqctx(req);
    	struct crypto_ablkcipher *geniv;
    
    	if (err == -EINPROGRESS)
    		return;
    
    	if (err)
    		goto out;
    
    	geniv = skcipher_givcrypt_reqtfm(req);
    	memcpy(req->creq.info, subreq->info, crypto_ablkcipher_ivsize(geniv));
    
    out:
    	kfree(subreq->info);
    }
    
    static void seqiv_complete(struct crypto_async_request *base, int err)
    {
    	struct skcipher_givcrypt_request *req = base->data;
    
    	seqiv_complete2(req, err);
    	skcipher_givcrypt_complete(req, err);
    }
    
    static void seqiv_aead_complete2(struct aead_givcrypt_request *req, int err)
    {
    	struct aead_request *subreq = aead_givcrypt_reqctx(req);
    	struct crypto_aead *geniv;
    
    	if (err == -EINPROGRESS)
    		return;
    
    	if (err)
    		goto out;
    
    	geniv = aead_givcrypt_reqtfm(req);
    	memcpy(req->areq.iv, subreq->iv, crypto_aead_ivsize(geniv));