Skip to content
Snippets Groups Projects
Select Git revision
  • a1eae7800eb73b76fb604d5510cbc42a5265be86
  • master default protected
  • android-msm-bullhead-3.10-nougat_kgdb_less_changes
  • android-msm-bullhead-3.10-nougat_kgdb
  • android-msm-bullhead-3.10-nougat_klist
  • android-4.4
  • android-msm-vega-4.4-oreo-daydream
  • android-msm-wahoo-4.4-p-preview-5
  • android-msm-wahoo-4.4-pie
  • android-msm-marlin-3.18-p-preview-5
  • android-msm-marlin-3.18-pie
  • android-msm-wahoo-2018.07-oreo-m2
  • android-msm-wahoo-2018.07-oreo-m4
  • android-msm-wahoo-4.4-p-preview-4
  • android-msm-bullhead-3.10-oreo-m6
  • android-msm-angler-3.10-oreo-m6
  • android-msm-marlin-3.18-p-preview-4
  • android-msm-stargazer-3.18-oreo-wear-dr
  • android-msm-catshark-3.18-oreo-wear-dr
  • android-msm-wahoo-4.4-oreo-m2
  • android-msm-wahoo-4.4-oreo-m4
  • android-daydreamos-8.0.0_r0.5
  • android-8.1.0_r0.92
  • android-8.1.0_r0.91
  • android-daydreamos-8.0.0_r0.4
  • android-p-preview-5_r0.2
  • android-p-preview-5_r0.1
  • android-9.0.0_r0.5
  • android-9.0.0_r0.4
  • android-9.0.0_r0.2
  • android-9.0.0_r0.1
  • android-8.1.0_r0.81
  • android-8.1.0_r0.80
  • android-8.1.0_r0.78
  • android-8.1.0_r0.76
  • android-8.1.0_r0.75
  • android-8.1.0_r0.72
  • android-8.1.0_r0.70
  • android-p-preview-4_r0.2
  • android-p-preview-4_r0.1
  • android-wear-8.0.0_r0.30
41 results

digsig.c

Blame
  • digsig.c 5.69 KiB
    /*
     * Copyright (C) 2011 Nokia Corporation
     * Copyright (C) 2011 Intel Corporation
     *
     * Author:
     * Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
     *                 <dmitry.kasatkin@intel.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, version 2 of the License.
     *
     * File: sign.c
     *	implements signature (RSA) verification
     *	pkcs decoding is based on LibTomCrypt code
     */
    
    #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
    
    #include <linux/err.h>
    #include <linux/module.h>
    #include <linux/slab.h>
    #include <linux/key.h>
    #include <linux/crypto.h>
    #include <crypto/hash.h>
    #include <crypto/sha.h>
    #include <keys/user-type.h>
    #include <linux/mpi.h>
    #include <linux/digsig.h>
    
    static struct crypto_shash *shash;
    
    static int pkcs_1_v1_5_decode_emsa(const unsigned char *msg,
    			unsigned long  msglen,
    			unsigned long  modulus_bitlen,
    			unsigned char *out,
    			unsigned long *outlen)
    {
    	unsigned long modulus_len, ps_len, i;
    
    	modulus_len = (modulus_bitlen >> 3) + (modulus_bitlen & 7 ? 1 : 0);
    
    	/* test message size */
    	if ((msglen > modulus_len) || (modulus_len < 11))
    		return -EINVAL;
    
    	/* separate encoded message */
    	if ((msg[0] != 0x00) || (msg[1] != (unsigned char)1))
    		return -EINVAL;
    
    	for (i = 2; i < modulus_len - 1; i++)
    		if (msg[i] != 0xFF)
    			break;
    
    	/* separator check */
    	if (msg[i] != 0)
    		/* There was no octet with hexadecimal value 0x00
    		to separate ps from m. */
    		return -EINVAL;
    
    	ps_len = i - 2;
    
    	if (*outlen < (msglen - (2 + ps_len + 1))) {
    		*outlen = msglen - (2 + ps_len + 1);
    		return -EOVERFLOW;
    	}
    
    	*outlen = (msglen - (2 + ps_len + 1));
    	memcpy(out, &msg[2 + ps_len + 1], *outlen);