aboutsummaryrefslogtreecommitdiff
path: root/openssl-1.1.0h/crypto/rsa/rsa_null.c
blob: d33949412022d959bf8340fe01ce6ebac69d07ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/bn.h>
#include "rsa_locl.h"

/*
 * This is a dummy RSA implementation that just returns errors when called.
 * It is designed to allow some RSA functions to work while stopping those
 * covered by the RSA patent. That is RSA, encryption, decryption, signing
 * and verify is not allowed but RSA key generation, key checking and other
 * operations (like storing RSA keys) are permitted.
 */

static int RSA_null_public_encrypt(int flen, const unsigned char *from,
                                   unsigned char *to, RSA *rsa, int padding);
static int RSA_null_private_encrypt(int flen, const unsigned char *from,
                                    unsigned char *to, RSA *rsa, int padding);
static int RSA_null_public_decrypt(int flen, const unsigned char *from,
                                   unsigned char *to, RSA *rsa, int padding);
static int RSA_null_private_decrypt(int flen, const unsigned char *from,
                                    unsigned char *to, RSA *rsa, int padding);
static int RSA_null_init(RSA *rsa);
static int RSA_null_finish(RSA *rsa);
static RSA_METHOD rsa_null_meth = {
    "Null RSA",
    RSA_null_public_encrypt,
    RSA_null_public_decrypt,
    RSA_null_private_encrypt,
    RSA_null_private_decrypt,
    NULL,
    NULL,
    RSA_null_init,
    RSA_null_finish,
    0,
    NULL,
    NULL,
    NULL,
    NULL
};

const RSA_METHOD *RSA_null_method(void)
{
    return (&rsa_null_meth);
}

static int RSA_null_public_encrypt(int flen, const unsigned char *from,
                                   unsigned char *to, RSA *rsa, int padding)
{
    RSAerr(RSA_F_RSA_NULL_PUBLIC_ENCRYPT, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
    return -1;
}

static int RSA_null_private_encrypt(int flen, const unsigned char *from,
                                    unsigned char *to, RSA *rsa, int padding)
{
    RSAerr(RSA_F_RSA_NULL_PRIVATE_ENCRYPT,
           RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
    return -1;
}

static int RSA_null_private_decrypt(int flen, const unsigned char *from,
                                    unsigned char *to, RSA *rsa, int padding)
{
    RSAerr(RSA_F_RSA_NULL_PRIVATE_DECRYPT,
           RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
    return -1;
}

static int RSA_null_public_decrypt(int flen, const unsigned char *from,
                                   unsigned char *to, RSA *rsa, int padding)
{
    RSAerr(RSA_F_RSA_NULL_PUBLIC_DECRYPT, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
    return -1;
}

static int RSA_null_init(RSA *rsa)
{
    return (1);
}

static int RSA_null_finish(RSA *rsa)
{
    return (1);
}