source: svn/trunk/newcon3bcm2_21bu/dta/src/bootloader/signature.c @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 1.7 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2010, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: $
11 * $brcm_Revision: $
12 * $brcm_Date: $
13 *
14 * Module Description: Digital signature processing routines
15 *
16 * Revision History:
17 *
18 * $brcm_Log: $
19 *
20 *
21 ***************************************************************************/
22
23#include "sha1/sha1o.h"
24
25/* forward declarations */
26void SHA1Compute_ram( uint8 * image_ptr, int len, uint32 * digest );
27int rsa_decrypt (void *in, void *pubkey, unsigned long *decrypted_digest);
28#if defined(RSA_BITS)
29#define DIGEST_SIZE     (RSA_BITS/8)
30#define SHA1_OFFSET     ((RSA_BITS/32) - 5)
31#else
32#define DIGEST_SIZE     0x80
33#define SHA1_OFFSET     27
34#endif
35
36int signature_check(unsigned long in, unsigned long size, unsigned long signature, unsigned long public_key)
37{
38   unsigned long sha1_output[5]; /* 20 bytes */
39   unsigned long decrypted_digest[DIGEST_SIZE/sizeof(unsigned long)];
40   int i;
41
42   SHA1Compute_ram((unsigned char *)in, size*8, sha1_output);
43
44    /* RSA decrypt the signature */
45   if (rsa_decrypt((unsigned long*)(signature), (unsigned long*)public_key, decrypted_digest))
46   {
47      /* Check SHA1 digest */
48      for (i=0; (i<5); i++)
49         if (decrypted_digest[SHA1_OFFSET+i] != sha1_output[i]) 
50            return 1;
51
52      return 0;
53   }
54     
55   return 1;   
56}
Note: See TracBrowser for help on using the repository browser.