1 | /*
|
---|
2 | * Copyright 1999-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 "rsa_locl.h"
|
---|
14 |
|
---|
15 | /*
|
---|
16 | * This is a dummy RSA implementation that just returns errors when called.
|
---|
17 | * It is designed to allow some RSA functions to work while stopping those
|
---|
18 | * covered by the RSA patent. That is RSA, encryption, decryption, signing
|
---|
19 | * and verify is not allowed but RSA key generation, key checking and other
|
---|
20 | * operations (like storing RSA keys) are permitted.
|
---|
21 | */
|
---|
22 |
|
---|
23 | static int RSA_null_public_encrypt(int flen, const unsigned char *from,
|
---|
24 | unsigned char *to, RSA *rsa, int padding);
|
---|
25 | static int RSA_null_private_encrypt(int flen, const unsigned char *from,
|
---|
26 | unsigned char *to, RSA *rsa, int padding);
|
---|
27 | static int RSA_null_public_decrypt(int flen, const unsigned char *from,
|
---|
28 | unsigned char *to, RSA *rsa, int padding);
|
---|
29 | static int RSA_null_private_decrypt(int flen, const unsigned char *from,
|
---|
30 | unsigned char *to, RSA *rsa, int padding);
|
---|
31 | static int RSA_null_init(RSA *rsa);
|
---|
32 | static int RSA_null_finish(RSA *rsa);
|
---|
33 | static RSA_METHOD rsa_null_meth = {
|
---|
34 | "Null RSA",
|
---|
35 | RSA_null_public_encrypt,
|
---|
36 | RSA_null_public_decrypt,
|
---|
37 | RSA_null_private_encrypt,
|
---|
38 | RSA_null_private_decrypt,
|
---|
39 | NULL,
|
---|
40 | NULL,
|
---|
41 | RSA_null_init,
|
---|
42 | RSA_null_finish,
|
---|
43 | 0,
|
---|
44 | NULL,
|
---|
45 | NULL,
|
---|
46 | NULL,
|
---|
47 | NULL
|
---|
48 | };
|
---|
49 |
|
---|
50 | const RSA_METHOD *RSA_null_method(void)
|
---|
51 | {
|
---|
52 | return (&rsa_null_meth);
|
---|
53 | }
|
---|
54 |
|
---|
55 | static int RSA_null_public_encrypt(int flen, const unsigned char *from,
|
---|
56 | unsigned char *to, RSA *rsa, int padding)
|
---|
57 | {
|
---|
58 | RSAerr(RSA_F_RSA_NULL_PUBLIC_ENCRYPT, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
|
---|
59 | return -1;
|
---|
60 | }
|
---|
61 |
|
---|
62 | static int RSA_null_private_encrypt(int flen, const unsigned char *from,
|
---|
63 | unsigned char *to, RSA *rsa, int padding)
|
---|
64 | {
|
---|
65 | RSAerr(RSA_F_RSA_NULL_PRIVATE_ENCRYPT,
|
---|
66 | RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
|
---|
67 | return -1;
|
---|
68 | }
|
---|
69 |
|
---|
70 | static int RSA_null_private_decrypt(int flen, const unsigned char *from,
|
---|
71 | unsigned char *to, RSA *rsa, int padding)
|
---|
72 | {
|
---|
73 | RSAerr(RSA_F_RSA_NULL_PRIVATE_DECRYPT,
|
---|
74 | RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
|
---|
75 | return -1;
|
---|
76 | }
|
---|
77 |
|
---|
78 | static int RSA_null_public_decrypt(int flen, const unsigned char *from,
|
---|
79 | unsigned char *to, RSA *rsa, int padding)
|
---|
80 | {
|
---|
81 | RSAerr(RSA_F_RSA_NULL_PUBLIC_DECRYPT, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
|
---|
82 | return -1;
|
---|
83 | }
|
---|
84 |
|
---|
85 | static int RSA_null_init(RSA *rsa)
|
---|
86 | {
|
---|
87 | return (1);
|
---|
88 | }
|
---|
89 |
|
---|
90 | static int RSA_null_finish(RSA *rsa)
|
---|
91 | {
|
---|
92 | return (1);
|
---|
93 | }
|
---|