source: EcnlProtoTool/trunk/openssl-1.1.0e/crypto/rsa/rsa_saos.c@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 2.7 KB
Line 
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#include <stdio.h>
11#include "internal/cryptlib.h"
12#include <openssl/bn.h>
13#include <openssl/rsa.h>
14#include <openssl/objects.h>
15#include <openssl/x509.h>
16
17int RSA_sign_ASN1_OCTET_STRING(int type,
18 const unsigned char *m, unsigned int m_len,
19 unsigned char *sigret, unsigned int *siglen,
20 RSA *rsa)
21{
22 ASN1_OCTET_STRING sig;
23 int i, j, ret = 1;
24 unsigned char *p, *s;
25
26 sig.type = V_ASN1_OCTET_STRING;
27 sig.length = m_len;
28 sig.data = (unsigned char *)m;
29
30 i = i2d_ASN1_OCTET_STRING(&sig, NULL);
31 j = RSA_size(rsa);
32 if (i > (j - RSA_PKCS1_PADDING_SIZE)) {
33 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,
34 RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
35 return (0);
36 }
37 s = OPENSSL_malloc((unsigned int)j + 1);
38 if (s == NULL) {
39 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE);
40 return (0);
41 }
42 p = s;
43 i2d_ASN1_OCTET_STRING(&sig, &p);
44 i = RSA_private_encrypt(i, s, sigret, rsa, RSA_PKCS1_PADDING);
45 if (i <= 0)
46 ret = 0;
47 else
48 *siglen = i;
49
50 OPENSSL_clear_free(s, (unsigned int)j + 1);
51 return (ret);
52}
53
54int RSA_verify_ASN1_OCTET_STRING(int dtype,
55 const unsigned char *m,
56 unsigned int m_len, unsigned char *sigbuf,
57 unsigned int siglen, RSA *rsa)
58{
59 int i, ret = 0;
60 unsigned char *s;
61 const unsigned char *p;
62 ASN1_OCTET_STRING *sig = NULL;
63
64 if (siglen != (unsigned int)RSA_size(rsa)) {
65 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,
66 RSA_R_WRONG_SIGNATURE_LENGTH);
67 return (0);
68 }
69
70 s = OPENSSL_malloc((unsigned int)siglen);
71 if (s == NULL) {
72 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, ERR_R_MALLOC_FAILURE);
73 goto err;
74 }
75 i = RSA_public_decrypt((int)siglen, sigbuf, s, rsa, RSA_PKCS1_PADDING);
76
77 if (i <= 0)
78 goto err;
79
80 p = s;
81 sig = d2i_ASN1_OCTET_STRING(NULL, &p, (long)i);
82 if (sig == NULL)
83 goto err;
84
85 if (((unsigned int)sig->length != m_len) ||
86 (memcmp(m, sig->data, m_len) != 0)) {
87 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING, RSA_R_BAD_SIGNATURE);
88 } else
89 ret = 1;
90 err:
91 ASN1_OCTET_STRING_free(sig);
92 OPENSSL_clear_free(s, (unsigned int)siglen);
93 return (ret);
94}
Note: See TracBrowser for help on using the repository browser.