Skip to content
Snippets Groups Projects
Select Git revision
  • a047330bce5d8c8057ad22eecba32999e3402f23
  • master default protected
  • 1.0.0
3 results

DCMotor.cpp

Blame
  • shash.c 17.54 KiB
    /*
     * Synchronous Cryptographic Hash operations.
     *
     * Copyright (c) 2008 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/scatterwalk.h>
    #include <crypto/internal/hash.h>
    #include <linux/err.h>
    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/slab.h>
    #include <linux/seq_file.h>
    #include <linux/cryptouser.h>
    #include <net/netlink.h>
    
    #include "internal.h"
    
    static const struct crypto_type crypto_shash_type;
    
    static int shash_no_setkey(struct crypto_shash *tfm, const u8 *key,
    			   unsigned int keylen)
    {
    	return -ENOSYS;
    }
    
    static int shash_setkey_unaligned(struct crypto_shash *tfm, const u8 *key,
    				  unsigned int keylen)
    {
    	struct shash_alg *shash = crypto_shash_alg(tfm);
    	unsigned long alignmask = crypto_shash_alignmask(tfm);
    	unsigned long absize;
    	u8 *buffer, *alignbuffer;
    	int err;
    
    	absize = keylen + (alignmask & ~(crypto_tfm_ctx_alignment() - 1));
    	buffer = kmalloc(absize, GFP_KERNEL);
    	if (!buffer)
    		return -ENOMEM;
    
    	alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
    	memcpy(alignbuffer, key, keylen);
    	err = shash->setkey(tfm, alignbuffer, keylen);
    	kzfree(buffer);
    	return err;
    }
    
    int crypto_shash_setkey(struct crypto_shash *tfm, const u8 *key,
    			unsigned int keylen)
    {
    	struct shash_alg *shash = crypto_shash_alg(tfm);
    	unsigned long alignmask = crypto_shash_alignmask(tfm);
    
    	if ((unsigned long)key & alignmask)
    		return shash_setkey_unaligned(tfm, key, keylen);
    
    	return shash->setkey(tfm, key, keylen);
    }
    EXPORT_SYMBOL_GPL(crypto_shash_setkey);
    
    static inline unsigned int shash_align_buffer_size(unsigned len,
    						   unsigned long mask)
    {
    	return len + (mask & ~(__alignof__(u8 __attribute__ ((aligned))) - 1));