1 --- crypto.c.orig 2004-03-21 04:02:32.000000000 -0800 2 +++ crypto.c 2018-10-15 15:18:25.842905000 -0700 3 @@ -56,6 +56,30 @@ 4 5 static EVP_PKEY *pkey; 6 7 +#if OPENSSL_VERSION_NUMBER < 0x10100000L 8 + 9 +static void *OPENSSL_zalloc (size_t num) 10 +{ 11 + void *ret = OPENSSL_malloc (num); 12 + 13 + if (ret != NULL) 14 + memset (ret, 0, num); 15 + return ret; 16 +} 17 + 18 +EVP_MD_CTX *EVP_MD_CTX_new (void) 19 +{ 20 + return OPENSSL_zalloc (sizeof (EVP_MD_CTX)); 21 +} 22 + 23 +void EVP_MD_CTX_free (EVP_MD_CTX *ctx) 24 +{ 25 + EVP_MD_CTX_cleanup (ctx); 26 + OPENSSL_free (ctx); 27 +} 28 + 29 +#endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */ 30 + 31 static void 32 opensslError (const char *what) 33 { 34 @@ -100,7 +124,7 @@ 35 SignFile (int fd, const char *filename, const char *sigfile) 36 { 37 const EVP_MD *mdType; 38 - EVP_MD_CTX ctx; 39 + EVP_MD_CTX *ctx; 40 ssize_t len; 41 unsigned char *sig = NULL; 42 unsigned int sigLen; 43 @@ -111,8 +135,12 @@ 44 if (!pkey) 45 return; 46 47 +#if OPENSSL_VERSION_NUMBER < 0x10100000L 48 mdType = EVP_PKEY_type (pkey->type) == EVP_PKEY_DSA ? EVP_dss1 () : 49 EVP_sha1 (); 50 +#else 51 + mdType = EVP_sha1 (); 52 +#endif 53 54 if (!sigfile) { 55 int tlen = strlen (filename) + 4 + 1; 56 @@ -122,21 +150,23 @@ 57 sigfile = tsigfile; 58 } 59 60 + if ((ctx = EVP_MD_CTX_new ()) == NULL) 61 + opensslError ("EVP_MD_CTX_new"); 62 #ifdef HAVE_EVP_MD_CTX_INIT 63 - EVP_MD_CTX_init (&ctx); 64 + EVP_MD_CTX_init (ctx); 65 #endif 66 #ifdef EVP_DIGESTINIT_VOID 67 - EVP_SignInit (&ctx, mdType); 68 + EVP_SignInit (ctx, mdType); 69 #else 70 - if (!EVP_SignInit (&ctx, mdType)) 71 + if (!EVP_SignInit (ctx, mdType)) 72 opensslError ("EVP_SignInit"); 73 #endif 74 75 while ((len = read (fd, HashBuffer, HASH_BUFFER_SIZE)) > 0) { 76 #ifdef EVP_DIGESTINIT_VOID 77 - EVP_SignUpdate (&ctx, HashBuffer, len); 78 + EVP_SignUpdate (ctx, HashBuffer, len); 79 #else 80 - if (!EVP_SignUpdate (&ctx, HashBuffer, len)) 81 + if (!EVP_SignUpdate (ctx, HashBuffer, len)) 82 opensslError ("EVP_SignUpdate"); 83 #endif 84 } 85 @@ -146,7 +176,7 @@ 86 87 sig = mymalloc (EVP_PKEY_size (pkey)); 88 89 - if (EVP_SignFinal (&ctx, sig, &sigLen, pkey)) { 90 + if (EVP_SignFinal (ctx, sig, &sigLen, pkey)) { 91 if ((f = open (sigfile, O_CREAT|O_WRONLY|O_TRUNC, 0600)) != -1) { 92 if (write (f, sig, sigLen) != sigLen) 93 yaficError (sigfile); 94 @@ -162,15 +192,16 @@ 95 if (sig) free (sig); 96 if (tsigfile) free (tsigfile); 97 #ifdef HAVE_EVP_MD_CTX_CLEANUP 98 - EVP_MD_CTX_cleanup (&ctx); 99 + EVP_MD_CTX_cleanup (ctx); 100 #endif 101 + EVP_MD_CTX_free (ctx); 102 } 103 104 void 105 VerifyFile (int fd, const char *filename, const char *sigfile) 106 { 107 const EVP_MD *mdType; 108 - EVP_MD_CTX ctx; 109 + EVP_MD_CTX *ctx; 110 ssize_t len; 111 unsigned char *sig = NULL; 112 int f; 113 @@ -181,8 +212,12 @@ 114 if (!pkey) 115 return; 116 117 +#if OPENSSL_VERSION_NUMBER < 0x10100000L 118 mdType = EVP_PKEY_type (pkey->type) == EVP_PKEY_DSA ? EVP_dss1 () : 119 EVP_sha1 (); 120 +#else 121 + mdType = EVP_sha1 (); 122 +#endif 123 124 if (!sigfile) { 125 int tlen = strlen (filename) + 4 + 1; 126 @@ -195,13 +230,15 @@ 127 fprintf (stderr, "Verifying %s: ", filename); 128 fflush (stderr); 129 130 + if ((ctx = EVP_MD_CTX_new ()) == NULL) 131 + opensslError ("EVP_MD_CTX_new"); 132 #ifdef HAVE_EVP_MD_CTX_INIT 133 - EVP_MD_CTX_init (&ctx); 134 + EVP_MD_CTX_init (ctx); 135 #endif 136 #ifdef EVP_DIGESTINIT_VOID 137 - EVP_VerifyInit (&ctx, mdType); 138 + EVP_VerifyInit (ctx, mdType); 139 #else 140 - if (!EVP_VerifyInit (&ctx, mdType)) { 141 + if (!EVP_VerifyInit (ctx, mdType)) { 142 fprintf (stderr, "Error\n"); 143 opensslError ("EVP_VerifyInit"); 144 } 145 @@ -209,9 +246,9 @@ 146 147 while ((len = read (fd, HashBuffer, HASH_BUFFER_SIZE)) > 0) { 148 #ifdef EVP_DIGESTINIT_VOID 149 - EVP_VerifyUpdate (&ctx, HashBuffer, len); 150 + EVP_VerifyUpdate (ctx, HashBuffer, len); 151 #else 152 - if (!EVP_VerifyUpdate (&ctx, HashBuffer, len)) { 153 + if (!EVP_VerifyUpdate (ctx, HashBuffer, len)) { 154 fprintf (stderr, "Error\n"); 155 opensslError ("EVP_SignUpdate"); 156 } 157 @@ -233,7 +270,7 @@ 158 159 close (f); 160 161 - ret = EVP_VerifyFinal (&ctx, sig, len, pkey); 162 + ret = EVP_VerifyFinal (ctx, sig, len, pkey); 163 if (ret < 0) { 164 fprintf (stderr, "Error\n"); 165 opensslError ("EVP_VerifyFinal"); 166 @@ -254,8 +291,9 @@ 167 if (sig) free (sig); 168 if (tsigfile) free (tsigfile); 169 #ifdef HAVE_EVP_MD_CTX_CLEANUP 170 - EVP_MD_CTX_cleanup (&ctx); 171 + EVP_MD_CTX_cleanup (ctx); 172 #endif 173 + EVP_MD_CTX_free (ctx); 174 } 175 176 const char * 177 @@ -265,7 +303,11 @@ 178 179 if (pkey) { 180 int bits = EVP_PKEY_bits (pkey); 181 +#if OPENSSL_VERSION_NUMBER < 0x10100000L 182 int type = EVP_PKEY_type (pkey->type); 183 +#else 184 + int type = EVP_PKEY_base_id (pkey); 185 +#endif 186 187 switch (type) { 188 case EVP_PKEY_RSA: 189