"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "apps/rsa.c" between
openssl-1.1.1f.tar.gz and openssl-1.1.1g.tar.gz

About: OpenSSL is a toolkit implementing the Transport Layer Security (TLS) protocols (including SSLv3) as well as a full-strength general purpose cryptographic library. Long Term Support (LTS) version (includes support for TLSv1.3).

rsa.c  (openssl-1.1.1f):rsa.c  (openssl-1.1.1g)
/* /*
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
* *
* Licensed under the OpenSSL license (the "License"). You may not use * Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy * this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at * in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html * https://www.openssl.org/source/license.html
*/ */
#include <openssl/opensslconf.h> #include <openssl/opensslconf.h>
#ifdef OPENSSL_NO_RSA #include <stdio.h>
NON_EMPTY_TRANSLATION_UNIT #include <stdlib.h>
#else #include <string.h>
#include <time.h>
# include <stdio.h> #include "apps.h"
# include <stdlib.h> #include "progs.h"
# include <string.h> #include <openssl/bio.h>
# include <time.h> #include <openssl/err.h>
# include "apps.h" #include <openssl/rsa.h>
# include "progs.h" #include <openssl/evp.h>
# include <openssl/bio.h> #include <openssl/x509.h>
# include <openssl/err.h> #include <openssl/pem.h>
# include <openssl/rsa.h> #include <openssl/bn.h>
# include <openssl/evp.h>
# include <openssl/x509.h>
# include <openssl/pem.h>
# include <openssl/bn.h>
typedef enum OPTION_choice { typedef enum OPTION_choice {
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
OPT_INFORM, OPT_OUTFORM, OPT_ENGINE, OPT_IN, OPT_OUT, OPT_INFORM, OPT_OUTFORM, OPT_ENGINE, OPT_IN, OPT_OUT,
OPT_PUBIN, OPT_PUBOUT, OPT_PASSOUT, OPT_PASSIN, OPT_PUBIN, OPT_PUBOUT, OPT_PASSOUT, OPT_PASSIN,
OPT_RSAPUBKEY_IN, OPT_RSAPUBKEY_OUT, OPT_RSAPUBKEY_IN, OPT_RSAPUBKEY_OUT,
/* Do not change the order here; see case statements below */ /* Do not change the order here; see case statements below */
OPT_PVK_NONE, OPT_PVK_WEAK, OPT_PVK_STRONG, OPT_PVK_NONE, OPT_PVK_WEAK, OPT_PVK_STRONG,
OPT_NOOUT, OPT_TEXT, OPT_MODULUS, OPT_CHECK, OPT_CIPHER OPT_NOOUT, OPT_TEXT, OPT_MODULUS, OPT_CHECK, OPT_CIPHER
} OPTION_CHOICE; } OPTION_CHOICE;
skipping to change at line 56 skipping to change at line 52
{"pubout", OPT_PUBOUT, '-', "Output a public key"}, {"pubout", OPT_PUBOUT, '-', "Output a public key"},
{"passout", OPT_PASSOUT, 's', "Output file pass phrase source"}, {"passout", OPT_PASSOUT, 's', "Output file pass phrase source"},
{"passin", OPT_PASSIN, 's', "Input file pass phrase source"}, {"passin", OPT_PASSIN, 's', "Input file pass phrase source"},
{"RSAPublicKey_in", OPT_RSAPUBKEY_IN, '-', "Input is an RSAPublicKey"}, {"RSAPublicKey_in", OPT_RSAPUBKEY_IN, '-', "Input is an RSAPublicKey"},
{"RSAPublicKey_out", OPT_RSAPUBKEY_OUT, '-', "Output is an RSAPublicKey"}, {"RSAPublicKey_out", OPT_RSAPUBKEY_OUT, '-', "Output is an RSAPublicKey"},
{"noout", OPT_NOOUT, '-', "Don't print key out"}, {"noout", OPT_NOOUT, '-', "Don't print key out"},
{"text", OPT_TEXT, '-', "Print the key in text"}, {"text", OPT_TEXT, '-', "Print the key in text"},
{"modulus", OPT_MODULUS, '-', "Print the RSA key modulus"}, {"modulus", OPT_MODULUS, '-', "Print the RSA key modulus"},
{"check", OPT_CHECK, '-', "Verify key consistency"}, {"check", OPT_CHECK, '-', "Verify key consistency"},
{"", OPT_CIPHER, '-', "Any supported cipher"}, {"", OPT_CIPHER, '-', "Any supported cipher"},
# if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4) #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4)
{"pvk-strong", OPT_PVK_STRONG, '-', "Enable 'Strong' PVK encoding level (def ault)"}, {"pvk-strong", OPT_PVK_STRONG, '-', "Enable 'Strong' PVK encoding level (def ault)"},
{"pvk-weak", OPT_PVK_WEAK, '-', "Enable 'Weak' PVK encoding level"}, {"pvk-weak", OPT_PVK_WEAK, '-', "Enable 'Weak' PVK encoding level"},
{"pvk-none", OPT_PVK_NONE, '-', "Don't enforce PVK encoding"}, {"pvk-none", OPT_PVK_NONE, '-', "Don't enforce PVK encoding"},
# endif #endif
# ifndef OPENSSL_NO_ENGINE #ifndef OPENSSL_NO_ENGINE
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
# endif #endif
{NULL} {NULL}
}; };
int rsa_main(int argc, char **argv) int rsa_main(int argc, char **argv)
{ {
ENGINE *e = NULL; ENGINE *e = NULL;
BIO *out = NULL; BIO *out = NULL;
RSA *rsa = NULL; RSA *rsa = NULL;
const EVP_CIPHER *enc = NULL; const EVP_CIPHER *enc = NULL;
char *infile = NULL, *outfile = NULL, *prog; char *infile = NULL, *outfile = NULL, *prog;
char *passin = NULL, *passout = NULL, *passinarg = NULL, *passoutarg = NULL; char *passin = NULL, *passout = NULL, *passinarg = NULL, *passoutarg = NULL;
int i, private = 0; int i, private = 0;
int informat = FORMAT_PEM, outformat = FORMAT_PEM, text = 0, check = 0; int informat = FORMAT_PEM, outformat = FORMAT_PEM, text = 0, check = 0;
int noout = 0, modulus = 0, pubin = 0, pubout = 0, ret = 1; int noout = 0, modulus = 0, pubin = 0, pubout = 0, ret = 1;
# if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4) #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4)
int pvk_encr = 2; int pvk_encr = 2;
# endif #endif
OPTION_CHOICE o; OPTION_CHOICE o;
prog = opt_init(argc, argv, rsa_options); prog = opt_init(argc, argv, rsa_options);
while ((o = opt_next()) != OPT_EOF) { while ((o = opt_next()) != OPT_EOF) {
switch (o) { switch (o) {
case OPT_EOF: case OPT_EOF:
case OPT_ERR: case OPT_ERR:
opthelp: opthelp:
BIO_printf(bio_err, "%s: Use -help for summary.\n", prog); BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
goto end; goto end;
skipping to change at line 133 skipping to change at line 129
break; break;
case OPT_RSAPUBKEY_IN: case OPT_RSAPUBKEY_IN:
pubin = 2; pubin = 2;
break; break;
case OPT_RSAPUBKEY_OUT: case OPT_RSAPUBKEY_OUT:
pubout = 2; pubout = 2;
break; break;
case OPT_PVK_STRONG: /* pvk_encr:= 2 */ case OPT_PVK_STRONG: /* pvk_encr:= 2 */
case OPT_PVK_WEAK: /* pvk_encr:= 1 */ case OPT_PVK_WEAK: /* pvk_encr:= 1 */
case OPT_PVK_NONE: /* pvk_encr:= 0 */ case OPT_PVK_NONE: /* pvk_encr:= 0 */
# if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4) #if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_RC4)
pvk_encr = (o - OPT_PVK_NONE); pvk_encr = (o - OPT_PVK_NONE);
# endif #endif
break; break;
case OPT_NOOUT: case OPT_NOOUT:
noout = 1; noout = 1;
break; break;
case OPT_TEXT: case OPT_TEXT:
text = 1; text = 1;
break; break;
case OPT_MODULUS: case OPT_MODULUS:
modulus = 1; modulus = 1;
break; break;
skipping to change at line 268 skipping to change at line 264
if (pubout || pubin) { if (pubout || pubin) {
if (pubout == 2) if (pubout == 2)
i = PEM_write_bio_RSAPublicKey(out, rsa); i = PEM_write_bio_RSAPublicKey(out, rsa);
else else
i = PEM_write_bio_RSA_PUBKEY(out, rsa); i = PEM_write_bio_RSA_PUBKEY(out, rsa);
} else { } else {
assert(private); assert(private);
i = PEM_write_bio_RSAPrivateKey(out, rsa, i = PEM_write_bio_RSAPrivateKey(out, rsa,
enc, NULL, 0, NULL, passout); enc, NULL, 0, NULL, passout);
} }
# ifndef OPENSSL_NO_DSA #ifndef OPENSSL_NO_DSA
} else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) { } else if (outformat == FORMAT_MSBLOB || outformat == FORMAT_PVK) {
EVP_PKEY *pk; EVP_PKEY *pk;
pk = EVP_PKEY_new(); pk = EVP_PKEY_new();
if (pk == NULL) if (pk == NULL)
goto end; goto end;
EVP_PKEY_set1_RSA(pk, rsa); EVP_PKEY_set1_RSA(pk, rsa);
if (outformat == FORMAT_PVK) { if (outformat == FORMAT_PVK) {
if (pubin) { if (pubin) {
BIO_printf(bio_err, "PVK form impossible with public key input\n "); BIO_printf(bio_err, "PVK form impossible with public key input\n ");
EVP_PKEY_free(pk); EVP_PKEY_free(pk);
goto end; goto end;
} }
assert(private); assert(private);
# ifdef OPENSSL_NO_RC4 # ifdef OPENSSL_NO_RC4
BIO_printf(bio_err, "PVK format not supported\n"); BIO_printf(bio_err, "PVK format not supported\n");
EVP_PKEY_free(pk); EVP_PKEY_free(pk);
goto end; goto end;
# else # else
i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout); i = i2b_PVK_bio(out, pk, pvk_encr, 0, passout);
# endif # endif
} else if (pubin || pubout) { } else if (pubin || pubout) {
i = i2b_PublicKey_bio(out, pk); i = i2b_PublicKey_bio(out, pk);
} else { } else {
assert(private); assert(private);
i = i2b_PrivateKey_bio(out, pk); i = i2b_PrivateKey_bio(out, pk);
} }
EVP_PKEY_free(pk); EVP_PKEY_free(pk);
# endif #endif
} else { } else {
BIO_printf(bio_err, "bad output format specified for outfile\n"); BIO_printf(bio_err, "bad output format specified for outfile\n");
goto end; goto end;
} }
if (i <= 0) { if (i <= 0) {
BIO_printf(bio_err, "unable to write key\n"); BIO_printf(bio_err, "unable to write key\n");
ERR_print_errors(bio_err); ERR_print_errors(bio_err);
} else { } else {
ret = 0; ret = 0;
} }
end: end:
release_engine(e); release_engine(e);
BIO_free_all(out); BIO_free_all(out);
RSA_free(rsa); RSA_free(rsa);
OPENSSL_free(passin); OPENSSL_free(passin);
OPENSSL_free(passout); OPENSSL_free(passout);
return ret; return ret;
} }
#endif
 End of changes. 15 change blocks. 
31 lines changed or deleted 27 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)