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