static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, int indent) { static const char fmt[]="%-18s"; char str[128]; const char *p; if (constructed & V_ASN1_CONSTRUCTED) p="cons: "; else p="prim: "; if (BIO_write(bp,p,6) < 6) goto err; BIO_indent(bp,indent,128); p=str; if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) BIO_snprintf(str,sizeof str,"priv [ %d ] ",tag); else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) BIO_snprintf(str,sizeof str,"cont [ %d ]",tag); else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) BIO_snprintf(str,sizeof str,"appl [ %d ]",tag); else if (tag > 30) BIO_snprintf(str,sizeof str,"<ASN1 %d>",tag); else p = ASN1_tag2str(tag); if (BIO_printf(bp,fmt,p) <= 0) goto err; return(1); err: return(0); }
int ip_to_string(char* oline, int oline_len, GENERAL_NAME* gen) { int i; unsigned char *p; char htmp[5]; p = gen->d.ip->data; if(gen->d.ip->length == 4) BIO_snprintf(oline, oline_len,"%d.%d.%d.%d", p[0], p[1], p[2], p[3]); //sizeof oline replaced by 40 else if(gen->d.ip->length == 16){ oline[0] = 0; for (i = 0; i < 8; i++){ BIO_snprintf(htmp, sizeof htmp,"%X", p[0] << 8 | p[1]); p += 2; g_strlcat(oline, htmp, oline_len); if (i != 7) g_strlcat(oline, ":", oline_len); } } else{ BIO_snprintf(oline, strlen((char*)oline), "IP Address <invalid>"); } syslog(LOG_INFO,"IP is: %s",oline); return 0; }
static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg) { unsigned char chflgs, chtmp; char tmphex[HEX_SIZE(long) + 3]; if (c > 0xffffffffL) return -1; if (c > 0xffff) { BIO_snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); if (!io_ch(arg, tmphex, 10)) return -1; return 10; } if (c > 0xff) { BIO_snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); if (!io_ch(arg, tmphex, 6)) return -1; return 6; } chtmp = (unsigned char)c; if (chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB; else chflgs = char_type[chtmp] & flags; if (chflgs & CHARTYPE_BS_ESC) { /* If we don't escape with quotes, signal we need quotes */ if (chflgs & ASN1_STRFLGS_ESC_QUOTE) { if (do_quotes) *do_quotes = 1; if (!io_ch(arg, &chtmp, 1)) return -1; return 1; } if (!io_ch(arg, "\\", 1)) return -1; if (!io_ch(arg, &chtmp, 1)) return -1; return 2; } if (chflgs & (ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB)) { BIO_snprintf(tmphex, 11, "\\%02X", chtmp); if (!io_ch(arg, tmphex, 3)) return -1; return 3; } /* * If we get this far and do any escaping at all must escape the escape * character itself: backslash. */ if (chtmp == '\\' && flags & ESC_FLAGS) { if (!io_ch(arg, "\\\\", 2)) return -1; return 2; } if (!io_ch(arg, &chtmp, 1)) return -1; return 1; }
void ERR_error_string_n(unsigned long e, char *buf, size_t len) { char lsbuf[64], fsbuf[64], rsbuf[64]; const char *ls, *fs, *rs; unsigned long l, f, r; if (len == 0) return; l = ERR_GET_LIB(e); f = ERR_GET_FUNC(e); r = ERR_GET_REASON(e); ls = ERR_lib_error_string(e); fs = ERR_func_error_string(e); rs = ERR_reason_error_string(e); if (ls == NULL) BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l); if (fs == NULL) BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f); if (rs == NULL) BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r); BIO_snprintf(buf, len, "error:%08lX:%s:%s:%s", e, ls ? ls : lsbuf, fs ? fs : fsbuf, rs ? rs : rsbuf); if (strlen(buf) == len - 1) { /* * output may be truncated; make sure we always have 5 * colon-separated fields, i.e. 4 colons ... */ #define NUM_COLONS 4 if (len > NUM_COLONS) { /* ... if possible */ int i; char *s = buf; for (i = 0; i < NUM_COLONS; i++) { char *colon = strchr(s, ':'); if (colon == NULL || colon > &buf[len - 1] - NUM_COLONS + i) { /* * set colon no. i at last possible position (buf[len-1] * is the terminating 0) */ colon = &buf[len - 1] - NUM_COLONS + i; *colon = ':'; } s = colon + 1; } } } }
ASN1_TIME *asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type) { char* p; ASN1_TIME *tmps = NULL; const size_t len = 20; if (type == V_ASN1_UNDEF) { if (is_utc(ts->tm_year)) type = V_ASN1_UTCTIME; else type = V_ASN1_GENERALIZEDTIME; } else if (type == V_ASN1_UTCTIME) { if (!is_utc(ts->tm_year)) goto err; } else if (type != V_ASN1_GENERALIZEDTIME) { goto err; } if (s == NULL) tmps = ASN1_STRING_new(); else tmps = s; if (tmps == NULL) return NULL; if (!ASN1_STRING_set(tmps, NULL, len)) goto err; tmps->type = type; p = (char*)tmps->data; if (type == V_ASN1_GENERALIZEDTIME) tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec); else tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec); #ifdef CHARSET_EBCDIC_not ebcdic2ascii(tmps->data, tmps->data, tmps->length); #endif return tmps; err: if (tmps != s) ASN1_STRING_free(tmps); return NULL; }
/* * See if the current malloc should fail. */ static int shouldfail(void) { int roll = (int)(random() % 100); int shoulditfail = roll < md_fail_percent; # ifndef _WIN32 /* suppressed on Windows as POSIX-like file descriptors are non-inheritable */ int len; char buff[80]; if (md_tracefd > 0) { BIO_snprintf(buff, sizeof(buff), "%c C%ld %%%d R%d\n", shoulditfail ? '-' : '+', md_count, md_fail_percent, roll); len = strlen(buff); if (write(md_tracefd, buff, len) != len) perror("shouldfail write failed"); # ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE if (shoulditfail) { void *addrs[30]; int num = backtrace(addrs, OSSL_NELEM(addrs)); backtrace_symbols_fd(addrs, num, md_tracefd); } # endif } # endif if (md_count) { /* If we used up this one, go to the next. */ if (--md_count == 0) parseit(); } return shoulditfail; }
static int file_find(OSSL_STORE_LOADER_CTX *ctx, OSSL_STORE_SEARCH *search) { /* * If ctx == NULL, the library is looking to know if this loader supports * the given search type. */ if (OSSL_STORE_SEARCH_get_type(search) == OSSL_STORE_SEARCH_BY_NAME) { unsigned long hash = 0; if (ctx == NULL) return 1; if (ctx->type != is_dir) { OSSL_STOREerr(OSSL_STORE_F_FILE_FIND, OSSL_STORE_R_SEARCH_ONLY_SUPPORTED_FOR_DIRECTORIES); return 0; } hash = X509_NAME_hash(OSSL_STORE_SEARCH_get0_name(search)); BIO_snprintf(ctx->_.dir.search_name, sizeof(ctx->_.dir.search_name), "%08lx", hash); return 1; } if (ctx != NULL) OSSL_STOREerr(OSSL_STORE_F_FILE_FIND, OSSL_STORE_R_UNSUPPORTED_SEARCH_TYPE); return 0; }
static int test_handshake(int idx) { SETUP_SSL_TEST_FIXTURE(); BIO_snprintf(fixture.test_app, sizeof(fixture.test_app), "test-%d", idx); EXECUTE_SSL_TEST(); }
/* Prepare the ENGINE structure for registration */ static int padlock_bind_helper(ENGINE *e) { /* Check available features */ padlock_available(); #if 1 /* disable RNG for now, see commentary in vicinity of RNG code */ padlock_use_rng=0; #endif /* Generate a nice engine name with available features */ BIO_snprintf(padlock_name, sizeof(padlock_name), "VIA PadLock (%s, %s)", padlock_use_rng ? "RNG" : "no-RNG", padlock_use_ace ? "ACE" : "no-ACE"); /* Register everything or return with an error */ if (!ENGINE_set_id(e, padlock_id) || !ENGINE_set_name(e, padlock_name) || !ENGINE_set_init_function(e, padlock_init) || #ifndef OPENSSL_NO_AES (padlock_use_ace && !ENGINE_set_ciphers (e, padlock_ciphers)) || #endif (padlock_use_rng && !ENGINE_set_RAND (e, &padlock_rand))) { return 0; } /* Everything looks good */ return 1; }
/* Prepare the ENGINE structure for registration */ static int padlock_bind_helper(ENGINE *e) { /* Check available features */ padlock_available(); /* * RNG is currently disabled for reasons discussed in commentary just * before padlock_rand_bytes function. */ padlock_use_rng = 0; /* Generate a nice engine name with available features */ BIO_snprintf(padlock_name, sizeof(padlock_name), "VIA PadLock (%s, %s)", padlock_use_rng ? "RNG" : "no-RNG", padlock_use_ace ? "ACE" : "no-ACE"); /* Register everything or return with an error */ if (!ENGINE_set_id(e, padlock_id) || !ENGINE_set_name(e, padlock_name) || !ENGINE_set_init_function(e, padlock_init) || # ifndef OPENSSL_NO_AES (padlock_use_ace && !ENGINE_set_ciphers(e, padlock_ciphers)) || # endif (padlock_use_rng && !ENGINE_set_RAND(e, &padlock_rand))) { return 0; } /* Everything looks good */ return 1; }
static int nss_cmd_evp_cert(NSS_CTX *ctx, void *p) { NSS_KEYCTX *keyctx = NULL; struct { EVP_PKEY *pkey; X509 *x509; } *param = p; switch (param->pkey->type) { case EVP_PKEY_RSA: { RSA *pkey_rsa = EVP_PKEY_get1_RSA(param->pkey); keyctx = RSA_get_ex_data(pkey_rsa, nss_rsa_ctx_index); RSA_free(pkey_rsa); } break; case EVP_PKEY_DSA: { DSA *pkey_dsa = EVP_PKEY_get1_DSA(param->pkey); keyctx = DSA_get_ex_data(pkey_dsa, nss_dsa_ctx_index); DSA_free(pkey_dsa); } break; default: { NSSerr(NSS_F_CMD_EVP_CERT, NSS_R_UNSUPPORTED_KEYTYPE); { /* add extra error message data */ char msgstr[10]; BIO_snprintf(msgstr, sizeof(msgstr), "%d", param->pkey->type); ERR_add_error_data(2, "KEYTYPE=", msgstr); } } break; } param->x509 = X509_from_CERTCertificate(keyctx->cert); return(param->x509 ? 1 : 0); }
void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) { CRYPTO_THREADID current_thread; char buf[ERR_ERROR_STRING_BUF_LEN]; char buf2[1024]; unsigned long thread_hash; const char *file; char *data; int line, flags; uint32_t packed_error; CRYPTO_THREADID_current(¤t_thread); thread_hash = CRYPTO_THREADID_hash(¤t_thread); for (;;) { packed_error = ERR_get_error_line_data(&file, &line, &data, &flags); if (packed_error == 0) { break; } ERR_error_string_n(packed_error, buf, sizeof(buf)); BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", thread_hash, buf, file, line, (flags & ERR_FLAG_STRING) ? data : ""); if (callback(buf2, strlen(buf2), ctx) <= 0) { break; } if (flags & ERR_FLAG_MALLOCED) { OPENSSL_free(data); } } }
void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), void *u) { unsigned long l; char buf[256]; char buf2[4096]; const char *file, *data; int line, flags; /* * We don't know what kind of thing CRYPTO_THREAD_ID is. Here is our best * attempt to convert it into something we can print. */ union { CRYPTO_THREAD_ID tid; unsigned long ltid; } tid; tid.ltid = 0; tid.tid = CRYPTO_THREAD_get_current_id(); while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) { ERR_error_string_n(l, buf, sizeof(buf)); BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf, file, line, (flags & ERR_TXT_STRING) ? data : ""); if (cb(buf2, strlen(buf2), u) <= 0) break; /* abort outputting the error report */ } }
const char *SSLeay_version(int t) { if (t == SSLEAY_VERSION) return OPENSSL_VERSION_TEXT; if (t == SSLEAY_BUILT_ON) { #ifdef DATE static char buf[sizeof(DATE)+11]; BIO_snprintf(buf,sizeof buf,"built on: %s",DATE); return(buf); #else return("built on: date not available"); #endif } if (t == SSLEAY_CFLAGS) { #ifdef CFLAGS static char buf[sizeof(CFLAGS)+11]; BIO_snprintf(buf,sizeof buf,"compiler: %s",CFLAGS); return(buf); #else return("compiler: information not available"); #endif } if (t == SSLEAY_PLATFORM) { #ifdef PLATFORM static char buf[sizeof(PLATFORM)+11]; BIO_snprintf(buf,sizeof buf,"platform: %s", PLATFORM); return(buf); #else return("platform: information not available"); #endif } if (t == SSLEAY_DIR) { #ifdef OPENSSLDIR return "OPENSSLDIR: \"" OPENSSLDIR "\""; #else return "OPENSSLDIR: N/A"; #endif } return("not available"); }
static unsigned int psk_client_cb(SSL *ssl, const char *hint, char *identity, unsigned int max_identity_len, unsigned char *psk, unsigned int max_psk_len) { unsigned int psk_len = 0; int ret; BIGNUM *bn = NULL; if (c_debug) BIO_printf(bio_c_out, "psk_client_cb\n"); if (!hint) { /* no ServerKeyExchange message */ if (c_debug) BIO_printf(bio_c_out, "NULL received PSK identity hint, continuing anyway\n"); } else if (c_debug) BIO_printf(bio_c_out, "Received PSK identity hint '%s'\n", hint); /* * lookup PSK identity and PSK key based on the given identity hint here */ ret = BIO_snprintf(identity, max_identity_len, "%s", psk_identity); if (ret < 0 || (unsigned int)ret > max_identity_len) goto out_err; if (c_debug) BIO_printf(bio_c_out, "created identity '%s' len=%d\n", identity, ret); ret = BN_hex2bn(&bn, psk_key); if (!ret) { BIO_printf(bio_err, "Could not convert PSK key '%s' to BIGNUM\n", psk_key); if (bn) BN_free(bn); return 0; } if ((unsigned int)BN_num_bytes(bn) > max_psk_len) { BIO_printf(bio_err, "psk buffer of callback is too small (%d) for key (%d)\n", max_psk_len, BN_num_bytes(bn)); BN_free(bn); return 0; } psk_len = BN_bn2bin(bn, psk); BN_free(bn); if (psk_len == 0) goto out_err; if (c_debug) BIO_printf(bio_c_out, "created PSK len=%d\n", psk_len); return psk_len; out_err: if (c_debug) BIO_printf(bio_err, "Error in PSK client callback\n"); return 0; }
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day, long offset_sec) { ASN1_GENERALIZEDTIME *alloced = NULL; char *p; struct tm *ts; struct tm data; size_t len = 20; if (s == NULL) alloced = s=M_ASN1_GENERALIZEDTIME_new(); if (s == NULL) return(NULL); ts=OPENSSL_gmtime(&t, &data); if (ts == NULL) { if(alloced) M_ASN1_GENERALIZEDTIME_free(alloced); return(NULL); } if (offset_day || offset_sec) { if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) { if(alloced) M_ASN1_GENERALIZEDTIME_free(alloced); return NULL; } } p=(char *)s->data; if ((p == NULL) || ((size_t)s->length < len)) { p= (char *) OPENSSL_malloc(len); if (p == NULL) { if(alloced) M_ASN1_GENERALIZEDTIME_free(alloced); ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE); return(NULL); } if (s->data != NULL) OPENSSL_free(s->data); s->data=(unsigned char *)p; } BIO_snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); s->length=op_strlen(p); s->type=V_ASN1_GENERALIZEDTIME; #ifdef CHARSET_EBCDIC_not ebcdic2ascii(s->data, s->data, s->length); #endif return(s); }
ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec) { char *p; struct tm *ts; struct tm data; size_t len = 20; int free_s = 0; if (s == NULL) { free_s = 1; s=M_ASN1_UTCTIME_new(); } if (s == NULL) goto err; ts=OPENSSL_gmtime(&t, &data); if (ts == NULL) goto err; if (offset_day || offset_sec) { if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) goto err; } if((ts->tm_year < 50) || (ts->tm_year >= 150)) goto err; p=(char *)s->data; if ((p == NULL) || ((size_t)s->length < len)) { p=OPENSSL_malloc(len); if (p == NULL) { ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE); goto err; } if (s->data != NULL) OPENSSL_free(s->data); s->data=(unsigned char *)p; } BIO_snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100, ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); s->length=strlen(p); s->type=V_ASN1_UTCTIME; #ifdef CHARSET_EBCDIC_not ebcdic2ascii(s->data, s->data, s->length); #endif return(s); err: if (free_s && s) M_ASN1_UTCTIME_free(s); return NULL; }
char *BN_options(void) { static int init=0; static char data[16]; if (!init) { init++; #ifdef BN_LLONG BIO_snprintf(data,sizeof data,"bn(%d,%d)", (int)sizeof(BN_ULLONG)*8,(int)sizeof(BN_ULONG)*8); #else BIO_snprintf(data,sizeof data,"bn(%d,%d)", (int)sizeof(BN_ULONG)*8,(int)sizeof(BN_ULONG)*8); #endif } return(data); }
static int test_big(void) { char buf[80]; /* Test excessively big number. Should fail */ if (!TEST_int_eq(BIO_snprintf(buf, sizeof(buf), "%f\n", 2 * (double)ULONG_MAX), -1)) return 0; return 1; }
static int test_j(int i) { const j_data *data = &jf_data[i]; char bio_buf[80]; BIO_snprintf(bio_buf, sizeof(bio_buf) - 1, data->format, data->value); if (!TEST_str_eq(bio_buf, data->expected)) return 0; return 1; }
int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x) { char pem_str[80]; if (!x->ameth || !x->ameth->param_encode) return 0; BIO_snprintf(pem_str, 80, "%s PARAMETERS", x->ameth->pem_str); return PEM_ASN1_write_bio((i2d_of_void *)x->ameth->param_encode, pem_str, bp, x, NULL, NULL, 0, 0, NULL); }
static const char *expected_greeting1(const char *name) { static char expected_greeting[256] = ""; BIO_snprintf(expected_greeting, sizeof(expected_greeting), "Hello OpenSSL %.20s, greetings from %s!", OPENSSL_VERSION_STR, name); return expected_greeting; }
static int noecho_console(UI *ui) { #ifdef TTY_FLAGS memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig)); tty_new.TTY_FLAGS &= ~ECHO; #endif #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS) if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1)) return 0; #endif #ifdef OPENSSL_SYS_VMS if (is_a_tty) { tty_new[0] = tty_orig[0]; tty_new[1] = tty_orig[1] | TT$M_NOECHO; tty_new[2] = tty_orig[2]; status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12, 0, 0, 0, 0); if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) { char tmp_num[2][12]; BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X", status); BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X", iosb.iosb$w_value); UIerr(UI_F_NOECHO_CONSOLE, UI_R_SYSQIOW_ERROR); ERR_add_error_data(5, "status=", tmp_num[0], ",", "iosb.iosb$w_value=", tmp_num[1]); return 0; } } #endif #if defined(_WIN32) && !defined(_WIN32_WCE) if (is_a_tty) { tty_new = tty_orig; tty_new &= ~ENABLE_ECHO_INPUT; SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), tty_new); } #endif return 1; }
void PEM_dek_info(char *buf, const char *type, int len, char *str) { long i; char *p = buf + strlen(buf); int j = PEM_BUFSIZE - (size_t)(p - buf), n; n = BIO_snprintf(p, j, "DEK-Info: %s,", type); if (n > 0) { j -= n; p += n; for (i = 0; i < len; i++) { n = BIO_snprintf(p, j, "%02X", 0xff & str[i]); if (n <= 0) return; j -= n; p += n; } if (j > 1) strcpy(p, "\n"); } }
static unsigned int clnt_psk_callback(SSL *ssl, const char *hint, char *ident, unsigned int max_ident_len, unsigned char *psk, unsigned int max_psk_len) { BIO_snprintf(ident, max_ident_len, "psk"); if (max_psk_len > 20) max_psk_len = 20; memset(psk, 0x5a, max_psk_len); return max_psk_len; }
int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cb, void *u) { char pem_str[80]; if (!x->ameth || x->ameth->priv_encode) return PEM_write_bio_PKCS8PrivateKey(bp, x, enc, (char *)kstr, klen, cb, u); BIO_snprintf(pem_str, 80, "%s PRIVATE KEY", x->ameth->pem_str); return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey, pem_str, bp, x, enc, kstr, klen, cb, u); }
int capi_rsa_priv_dec(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding) { int i; unsigned char *tmpbuf; CAPI_KEY *capi_key; CAPI_CTX *ctx; ctx = ENGINE_get_ex_data(rsa->engine, capi_idx); CAPI_trace(ctx, "Called capi_rsa_priv_dec()\n"); capi_key = RSA_get_ex_data(rsa, rsa_capi_idx); if (!capi_key) { CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, CAPI_R_CANT_GET_KEY); return -1; } if(padding != RSA_PKCS1_PADDING) { char errstr[10]; BIO_snprintf(errstr, 10, "%d", padding); CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, CAPI_R_UNSUPPORTED_PADDING); ERR_add_error_data(2, "padding=", errstr); return -1; } /* Create temp reverse order version of input */ if(!(tmpbuf = OPENSSL_malloc(flen)) ) { CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, ERR_R_MALLOC_FAILURE); return -1; } for(i = 0; i < flen; i++) tmpbuf[flen - i - 1] = from[i]; /* Finally decrypt it */ if(!CryptDecrypt(capi_key->key, 0, TRUE, 0, tmpbuf, &flen)) { CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, CAPI_R_DECRYPT_ERROR); capi_addlasterror(); OPENSSL_free(tmpbuf); return -1; } else memcpy(to, tmpbuf, flen); OPENSSL_free(tmpbuf); return flen; }
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day, long offset_sec) { char *p; struct tm *ts; struct tm data; size_t len = 20; ASN1_GENERALIZEDTIME *tmps = NULL; if (s == NULL) tmps = ASN1_GENERALIZEDTIME_new(); else tmps = s; if (tmps == NULL) return NULL; ts = OPENSSL_gmtime(&t, &data); if (ts == NULL) goto err; if (offset_day || offset_sec) { if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) goto err; } p = (char *)tmps->data; if ((p == NULL) || ((size_t)tmps->length < len)) { p = OPENSSL_malloc(len); if (p == NULL) { ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE); goto err; } OPENSSL_free(tmps->data); tmps->data = (unsigned char *)p; } BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec); tmps->length = strlen(p); tmps->type = V_ASN1_GENERALIZEDTIME; #ifdef CHARSET_EBCDIC_not ebcdic2ascii(tmps->data, tmps->data, tmps->length); #endif return tmps; err: if (s == NULL) ASN1_GENERALIZEDTIME_free(tmps); return NULL; }
static int test_query_cache_stochastic(void) { const int max = 10000, tail = 10; OSSL_METHOD_STORE *store; int i, res = 0; char buf[50]; void *result; int errors = 0; int v[10001]; if (!TEST_ptr(store = ossl_method_store_new(NULL)) || !add_property_names("n", NULL)) goto err; for (i = 1; i <= max; i++) { v[i] = 2 * i; BIO_snprintf(buf, sizeof(buf), "n=%d\n", i); if (!TEST_true(ossl_method_store_add(store, i, buf, "abc", NULL)) || !TEST_true(ossl_method_store_cache_set(store, i, buf, v + i)) || !TEST_true(ossl_method_store_cache_set(store, i, "n=1234", "miss"))) { TEST_note("iteration %d", i); goto err; } } for (i = 1; i <= max; i++) { BIO_snprintf(buf, sizeof(buf), "n=%d\n", i); if (!ossl_method_store_cache_get(store, i, buf, &result) || result != v + i) errors++; } /* There is a tiny probability that this will fail when it shouldn't */ res = TEST_int_gt(errors, tail) && TEST_int_lt(errors, max - tail); err: ossl_method_store_free(store); return res; }
static void check_message(const struct set_name_fn *fn, const char *op, const char *nameincert, int match, const char *name) { char msg[1024]; if (match < 0) return; BIO_snprintf(msg, sizeof(msg), "%s: %s: [%s] %s [%s]", fn->name, op, nameincert, match ? "matches" : "does not match", name); if (is_exception(msg)) return; puts(msg); ++errors; }