Skip to content
Snippets Groups Projects
Select Git revision
  • c2740a87ca989ca42b0c078e021654e247a08311
  • vme-testing default
  • ci-test
  • master
  • remoteproc
  • am625-sk-ov5640
  • pcal6534-upstreaming
  • lps22df-upstreaming
  • msc-upstreaming
  • imx8mp
  • iio/noa1305
  • vme-next
  • vme-next-4.14-rc4
  • v4.14-rc4
  • v4.14-rc3
  • v4.14-rc2
  • v4.14-rc1
  • v4.13
  • vme-next-4.13-rc7
  • v4.13-rc7
  • v4.13-rc6
  • v4.13-rc5
  • v4.13-rc4
  • v4.13-rc3
  • v4.13-rc2
  • v4.13-rc1
  • v4.12
  • v4.12-rc7
  • v4.12-rc6
  • v4.12-rc5
  • v4.12-rc4
  • v4.12-rc3
32 results

builtin-script.c

Blame
  • ansi_cprng.c 10.92 KiB
    /*
     * PRNG: Pseudo Random Number Generator
     *       Based on NIST Recommended PRNG From ANSI X9.31 Appendix A.2.4 using
     *       AES 128 cipher
     *
     *  (C) Neil Horman <nhorman@tuxdriver.com>
     *
     *  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
     *  any later version.
     *
     *
     */
    
    #include <crypto/internal/rng.h>
    #include <linux/err.h>
    #include <linux/init.h>
    #include <linux/module.h>
    #include <linux/moduleparam.h>
    #include <linux/string.h>
    
    #define DEFAULT_PRNG_KEY "0123456789abcdef"
    #define DEFAULT_PRNG_KSZ 16
    #define DEFAULT_BLK_SZ 16
    #define DEFAULT_V_SEED "zaybxcwdveuftgsh"
    
    /*
     * Flags for the prng_context flags field
     */
    
    #define PRNG_FIXED_SIZE 0x1
    #define PRNG_NEED_RESET 0x2
    
    /*
     * Note: DT is our counter value
     *	 I is our intermediate value
     *	 V is our seed vector
     * See http://csrc.nist.gov/groups/STM/cavp/documents/rng/931rngext.pdf
     * for implementation details
     */
    
    
    struct prng_context {
    	spinlock_t prng_lock;
    	unsigned char rand_data[DEFAULT_BLK_SZ];
    	unsigned char last_rand_data[DEFAULT_BLK_SZ];
    	unsigned char DT[DEFAULT_BLK_SZ];
    	unsigned char I[DEFAULT_BLK_SZ];
    	unsigned char V[DEFAULT_BLK_SZ];
    	u32 rand_data_valid;
    	struct crypto_cipher *tfm;
    	u32 flags;
    };
    
    static int dbg;
    
    static void hexdump(char *note, unsigned char *buf, unsigned int len)
    {
    	if (dbg) {
    		printk(KERN_CRIT "%s", note);
    		print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
    				16, 1,
    				buf, len, false);
    	}
    }
    
    #define dbgprint(format, args...) do {\
    if (dbg)\
    	printk(format, ##args);\