repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
psk_client_cb
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; }
/*char *psk_key=NULL; by default PSK is not used */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/s_client.c#L220-L275
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
psk_server_cb
static unsigned int psk_server_cb(SSL *ssl, const char *identity, unsigned char *psk, unsigned int max_psk_len) { unsigned int psk_len = 0; int ret; BIGNUM *bn = NULL; if (s_debug) BIO_printf(bio_s_out,"psk_server_cb\n"); if (!identity) { BIO_printf(bio_err,"Error: client did not send PSK identity\n"); goto out_err; } if (s_debug) BIO_printf(bio_s_out,"identity_len=%d identity=%s\n", identity ? (int)strlen(identity) : 0, identity); /* here we could lookup the given identity e.g. from a database */ if (strcmp(identity, psk_identity) != 0) { BIO_printf(bio_s_out, "PSK error: client identity not found" " (got '%s' expected '%s')\n", identity, psk_identity); goto out_err; } if (s_debug) BIO_printf(bio_s_out, "PSK client identity found\n"); /* convert the PSK key to binary */ 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 (BN_num_bytes(bn) > (int)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; } ret = BN_bn2bin(bn, psk); BN_free(bn); if (ret < 0) goto out_err; psk_len = (unsigned int)ret; if (s_debug) BIO_printf(bio_s_out, "fetched PSK len=%d\n", psk_len); return psk_len; out_err: if (s_debug) BIO_printf(bio_err, "Error in PSK server callback\n"); return 0; }
/* by default PSK is not used */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/s_server.c#L309-L369
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
cert_status_cb
static int cert_status_cb(SSL *s, void *arg) { tlsextstatusctx *srctx = arg; BIO *err = srctx->err; char *host, *port, *path; int use_ssl; unsigned char *rspder = NULL; int rspderlen; STACK_OF(OPENSSL_STRING) *aia = NULL; X509 *x = NULL; X509_STORE_CTX inctx; X509_OBJECT obj; OCSP_REQUEST *req = NULL; OCSP_RESPONSE *resp = NULL; OCSP_CERTID *id = NULL; STACK_OF(X509_EXTENSION) *exts; int ret = SSL_TLSEXT_ERR_NOACK; int i; #if 0 STACK_OF(OCSP_RESPID) *ids; SSL_get_tlsext_status_ids(s, &ids); BIO_printf(err, "cert_status: received %d ids\n", sk_OCSP_RESPID_num(ids)); #endif if (srctx->verbose) BIO_puts(err, "cert_status: callback called\n"); /* Build up OCSP query from server certificate */ x = SSL_get_certificate(s); aia = X509_get1_ocsp(x); if (aia) { if (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0), &host, &port, &path, &use_ssl)) { BIO_puts(err, "cert_status: can't parse AIA URL\n"); goto err; } if (srctx->verbose) BIO_printf(err, "cert_status: AIA URL: %s\n", sk_OPENSSL_STRING_value(aia, 0)); } else { if (!srctx->host) { BIO_puts(srctx->err, "cert_status: no AIA and no default responder URL\n"); goto done; } host = srctx->host; path = srctx->path; port = srctx->port; use_ssl = srctx->use_ssl; } if (!X509_STORE_CTX_init(&inctx, SSL_CTX_get_cert_store(SSL_get_SSL_CTX(s)), NULL, NULL)) goto err; if (X509_STORE_get_by_subject(&inctx,X509_LU_X509, X509_get_issuer_name(x),&obj) <= 0) { BIO_puts(err, "cert_status: Can't retrieve issuer certificate.\n"); X509_STORE_CTX_cleanup(&inctx); goto done; } req = OCSP_REQUEST_new(); if (!req) goto err; id = OCSP_cert_to_id(NULL, x, obj.data.x509); X509_free(obj.data.x509); X509_STORE_CTX_cleanup(&inctx); if (!id) goto err; if (!OCSP_request_add0_id(req, id)) goto err; id = NULL; /* Add any extensions to the request */ SSL_get_tlsext_status_exts(s, &exts); for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) { X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i); if (!OCSP_REQUEST_add_ext(req, ext, -1)) goto err; } resp = process_responder(err, req, host, path, port, use_ssl, NULL, srctx->timeout); if (!resp) { BIO_puts(err, "cert_status: error querying responder\n"); goto done; } rspderlen = i2d_OCSP_RESPONSE(resp, &rspder); if (rspderlen <= 0) goto err; SSL_set_tlsext_status_ocsp_resp(s, rspder, rspderlen); if (srctx->verbose) { BIO_puts(err, "cert_status: ocsp response sent:\n"); OCSP_RESPONSE_print(err, resp, 2); } ret = SSL_TLSEXT_ERR_OK; done: if (ret != SSL_TLSEXT_ERR_OK) ERR_print_errors(err); if (aia) { OPENSSL_free(host); OPENSSL_free(path); OPENSSL_free(port); X509_email_free(aia); } if (id) OCSP_CERTID_free(id); if (req) OCSP_REQUEST_free(req); if (resp) OCSP_RESPONSE_free(resp); return ret; err: ret = SSL_TLSEXT_ERR_ALERT_FATAL; goto done; }
/* Certificate Status callback. This is called when a client includes a * certificate status request extension. * * This is a simplified version. It examines certificates each time and * makes one OCSP responder query for each request. * * A full version would store details such as the OCSP certificate IDs and * minimise the number of OCSP responses by caching them until they were * considered "expired". */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/s_server.c#L708-L828
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
s_time_usage
static void s_time_usage(void) { static char umsg[] = "\ -time arg - max number of seconds to collect data, default %d\n\ -verify arg - turn on peer certificate verification, arg == depth\n\ -cert arg - certificate file to use, PEM format assumed\n\ -key arg - RSA file to use, PEM format assumed, key is in cert file\n\ file if not specified by this option\n\ -CApath arg - PEM format directory of CA's\n\ -CAfile arg - PEM format file of CA's\n\ -cipher - preferred cipher to use, play with 'openssl ciphers'\n\n"; printf( "usage: s_time <args>\n\n" ); printf("-connect host:port - host:port to connect to (default is %s)\n",SSL_CONNECT_NAME); #ifdef FIONBIO printf("-nbio - Run with non-blocking IO\n"); printf("-ssl2 - Just use SSLv2\n"); printf("-ssl3 - Just use SSLv3\n"); printf("-bugs - Turn on SSL bug compatibility\n"); printf("-new - Just time new connections\n"); printf("-reuse - Just time connection reuse\n"); printf("-www page - Retrieve 'page' from the site\n"); #endif printf( umsg,SECONDS ); }
/*********************************************************************** * usage - display usage message */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/s_time.c#L172-L197
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
parseArgs
static int parseArgs(int argc, char **argv) { int badop = 0; verify_depth=0; verify_error=X509_V_OK; argc--; argv++; while (argc >= 1) { if (strcmp(*argv,"-connect") == 0) { if (--argc < 1) goto bad; host= *(++argv); } #if 0 else if( strcmp(*argv,"-host") == 0) { if (--argc < 1) goto bad; host= *(++argv); } else if( strcmp(*argv,"-port") == 0) { if (--argc < 1) goto bad; port= *(++argv); } #endif else if (strcmp(*argv,"-reuse") == 0) perform=2; else if (strcmp(*argv,"-new") == 0) perform=1; else if( strcmp(*argv,"-verify") == 0) { tm_verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE; if (--argc < 1) goto bad; verify_depth=atoi(*(++argv)); BIO_printf(bio_err,"verify depth is %d\n",verify_depth); } else if( strcmp(*argv,"-cert") == 0) { if (--argc < 1) goto bad; t_cert_file= *(++argv); } else if( strcmp(*argv,"-key") == 0) { if (--argc < 1) goto bad; t_key_file= *(++argv); } else if( strcmp(*argv,"-CApath") == 0) { if (--argc < 1) goto bad; CApath= *(++argv); } else if( strcmp(*argv,"-CAfile") == 0) { if (--argc < 1) goto bad; CAfile= *(++argv); } else if( strcmp(*argv,"-cipher") == 0) { if (--argc < 1) goto bad; tm_cipher= *(++argv); } #ifdef FIONBIO else if(strcmp(*argv,"-nbio") == 0) { t_nbio=1; } #endif else if(strcmp(*argv,"-www") == 0) { if (--argc < 1) goto bad; s_www_path= *(++argv); if(strlen(s_www_path) > MYBUFSIZ-100) { BIO_printf(bio_err,"-www option too long\n"); badop=1; } } else if(strcmp(*argv,"-bugs") == 0) st_bugs=1; #ifndef OPENSSL_NO_SSL2 else if(strcmp(*argv,"-ssl2") == 0) s_time_meth=SSLv2_client_method(); #endif #ifndef OPENSSL_NO_SSL3 else if(strcmp(*argv,"-ssl3") == 0) s_time_meth=SSLv3_client_method(); #endif else if( strcmp(*argv,"-time") == 0) { if (--argc < 1) goto bad; maxTime= atoi(*(++argv)); } else { BIO_printf(bio_err,"unknown option %s\n",*argv); badop=1; break; } argc--; argv++; } if (perform == 0) perform=3; if(badop) { bad: s_time_usage(); return -1; } return 0; /* Valid args */ } /*********************************************************************** * TIME - time functions */ #define START 0 #define STOP 1 static double tm_Time_F(int s) { return app_tminterval(s,1); } /*********************************************************************** * MAIN - main processing area for client * real name depends on MONOLITH */ int MAIN(int, char **); int MAIN(int argc, char **argv) { double totalTime = 0.0; int nConn = 0; SSL *scon=NULL; long finishtime=0; int ret=1,i; MS_STATIC char buf[1024*8]; int ver; apps_startup(); s_time_init(); if (bio_err == NULL) bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3) s_time_meth=SSLv23_client_method(); #elif !defined(OPENSSL_NO_SSL3) s_time_meth=SSLv3_client_method(); #elif !defined(OPENSSL_NO_SSL2) s_time_meth=SSLv2_client_method(); #endif /* parse the command line arguments */ if( parseArgs( argc, argv ) < 0 ) goto end; OpenSSL_add_ssl_algorithms(); if ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1); SSL_CTX_set_quiet_shutdown(tm_ctx,1); if (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL); SSL_CTX_set_cipher_list(tm_ctx,tm_cipher); if(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file)) goto end; SSL_load_error_strings(); if ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) || (!SSL_CTX_set_default_verify_paths(tm_ctx))) { /* BIO_printf(bio_err,"error setting default verify locations\n"); */ ERR_print_errors(bio_err); /* goto end; */ } if (tm_cipher == NULL) tm_cipher = getenv("SSL_CIPHER"); if (tm_cipher == NULL ) { fprintf( stderr, "No CIPHER specified\n" ); } if (!(perform & 1)) goto next; printf( "Collecting connection statistics for %d seconds\n", maxTime ); /* Loop and time how long it takes to make connections */ bytes_read=0; finishtime=(long)time(NULL)+maxTime; tm_Time_F(START); for (;;) { if (finishtime < (long)time(NULL)) break; #ifdef WIN32_STUFF if( flushWinMsgs(0) == -1 ) goto end; if( waitingToDie || exitNow ) /* we're dead */ goto end; #endif if( (scon = doConnection( NULL )) == NULL ) goto end; if (s_www_path != NULL) { BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); SSL_write(scon,buf,strlen(buf)); while ((i=SSL_read(scon,buf,sizeof(buf))) > 0) bytes_read+=i; } #ifdef NO_SHUTDOWN SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); #else SSL_shutdown(scon); #endif SHUTDOWN2(SSL_get_fd(scon)); nConn += 1; if (SSL_session_reused(scon)) ver='r'; else { ver=SSL_version(scon); if (ver == TLS1_VERSION) ver='t'; else if (ver == SSL3_VERSION) ver='3'; else if (ver == SSL2_VERSION) ver='2'; else ver='*'; } fputc(ver,stdout); fflush(stdout); SSL_free( scon ); scon=NULL; } totalTime += tm_Time_F(STOP); /* Add the time for this iteration */ i=(int)((long)time(NULL)-finishtime+maxTime); printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read); printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn); /* Now loop and time connections using the same session id over and over */ next: if (!(perform & 2)) goto end; printf( "\n\nNow timing with session id reuse.\n" ); /* Get an SSL object so we can reuse the session id */ if( (scon = doConnection( NULL )) == NULL ) { fprintf( stderr, "Unable to get connection\n" ); goto end; } if (s_www_path != NULL) { BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); SSL_write(scon,buf,strlen(buf)); while (SSL_read(scon,buf,sizeof(buf)) > 0) ; } #ifdef NO_SHUTDOWN SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); #else SSL_shutdown(scon); #endif SHUTDOWN2(SSL_get_fd(scon)); nConn = 0; totalTime = 0.0; finishtime=(long)time(NULL)+maxTime; printf( "starting\n" ); bytes_read=0; tm_Time_F(START); for (;;) { if (finishtime < (long)time(NULL)) break; #ifdef WIN32_STUFF if( flushWinMsgs(0) == -1 ) goto end; if( waitingToDie || exitNow ) /* we're dead */ goto end; #endif if( (doConnection( scon )) == NULL ) goto end; if (s_www_path) { BIO_snprintf(buf,sizeof buf,"GET %s HTTP/1.0\r\n\r\n",s_www_path); SSL_write(scon,buf,strlen(buf)); while ((i=SSL_read(scon,buf,sizeof(buf))) > 0) bytes_read+=i; } #ifdef NO_SHUTDOWN SSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); #else SSL_shutdown(scon); #endif SHUTDOWN2(SSL_get_fd(scon)); nConn += 1; if (SSL_session_reused(scon)) ver='r'; else { ver=SSL_version(scon); if (ver == TLS1_VERSION) ver='t'; else if (ver == SSL3_VERSION) ver='3'; else if (ver == SSL2_VERSION) ver='2'; else ver='*'; } fputc(ver,stdout); fflush(stdout); } totalTime += tm_Time_F(STOP); /* Add the time for this iteration*/ printf( "\n\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read); printf( "%d connections in %ld real seconds, %ld bytes read per connection\n",nConn,(long)time(NULL)-finishtime+maxTime,bytes_read/nConn); ret=0; end: if (scon != NULL) SSL_free(scon); if (tm_ctx != NULL) { SSL_CTX_free(tm_ctx); tm_ctx=NULL; } apps_shutdown(); OPENSSL_EXIT(ret); } /*********************************************************************** * doConnection - make a connection * Args: * scon = earlier ssl connection for session id, or NULL * Returns: * SSL * = the connection pointer. */ static SSL *doConnection(SSL *scon) { BIO *conn; SSL *serverCon; int width, i; fd_set readfds; if ((conn=BIO_new(BIO_s_connect())) == NULL) return(NULL); /* BIO_set_conn_port(conn,port);*/ BIO_set_conn_hostname(conn,host); if (scon == NULL) serverCon=SSL_new(tm_ctx); else { serverCon=scon; SSL_set_connect_state(serverCon); } SSL_set_bio(serverCon,conn,conn); #if 0 if( scon != NULL ) SSL_set_session(serverCon,SSL_get_session(scon)); #endif /* ok, lets connect */ for(;;) { i=SSL_connect(serverCon); if (BIO_sock_should_retry(i)) { BIO_printf(bio_err,"DELAY\n"); i=SSL_get_fd(serverCon); width=i+1; FD_ZERO(&readfds); openssl_fdset(i,&readfds); /* Note: under VMS with SOCKETSHR the 2nd parameter * is currently of type (int *) whereas under other * systems it is (void *) if you don't have a cast it * will choke the compiler: if you do have a cast then * you can either go for (int *) or (void *). */ select(width,(void *)&readfds,NULL,NULL,NULL); continue; } break; } if(i <= 0) { BIO_printf(bio_err,"ERROR\n"); if (verify_error != X509_V_OK) BIO_printf(bio_err,"verify error:%s\n", X509_verify_cert_error_string(verify_error)); else ERR_print_errors(bio_err); if (scon == NULL) SSL_free(serverCon); return NULL; } return serverCon; }
/*********************************************************************** * parseArgs - Parse command line arguments and initialize data * * Returns 0 if ok, -1 on bad args */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/s_time.c#L204-L630
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
smime_cb
static int smime_cb(int ok, X509_STORE_CTX *ctx) { int error; error = X509_STORE_CTX_get_error(ctx); if ((error != X509_V_ERR_NO_EXPLICIT_POLICY) && ((error != X509_V_OK) || (ok != 2))) return ok; policies_print(NULL, ctx); return ok; }
/* Minimal callback just to output policy info (if any) */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/smime.c#L843-L857
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
query_command
static int query_command(const char *data, char *digest, const EVP_MD *md, const char *policy, int no_nonce, int cert, const char *in, const char *out, int text) { int ret = 0; TS_REQ *query = NULL; BIO *in_bio = NULL; BIO *data_bio = NULL; BIO *out_bio = NULL; /* Build query object either from file or from scratch. */ if (in != NULL) { if ((in_bio = BIO_new_file(in, "rb")) == NULL) goto end; query = d2i_TS_REQ_bio(in_bio, NULL); } else { /* Open the file if no explicit digest bytes were specified. */ if (!digest && !(data_bio = BIO_open_with_default(data, "rb", stdin))) goto end; /* Creating the query object. */ query = create_query(data_bio, digest, md, policy, no_nonce, cert); /* Saving the random number generator state. */ } if (query == NULL) goto end; /* Write query either in ASN.1 or in text format. */ if ((out_bio = BIO_open_with_default(out, "wb", stdout)) == NULL) goto end; if (text) { /* Text output. */ if (!TS_REQ_print_bio(out_bio, query)) goto end; } else { /* ASN.1 output. */ if (!i2d_TS_REQ_bio(out_bio, query)) goto end; } ret = 1; end: ERR_print_errors(bio_err); /* Clean up. */ BIO_free_all(in_bio); BIO_free_all(data_bio); BIO_free_all(out_bio); TS_REQ_free(query); return ret; }
/* * Query-related method definitions. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/ts.c#L466-L523
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
reply_command
static int reply_command(CONF *conf, char *section, char *engine, char *queryfile, char *passin, char *inkey, char *signer, char *chain, const char *policy, char *in, int token_in, char *out, int token_out, int text) { int ret = 0; TS_RESP *response = NULL; BIO *in_bio = NULL; BIO *query_bio = NULL; BIO *inkey_bio = NULL; BIO *signer_bio = NULL; BIO *out_bio = NULL; /* Build response object either from response or query. */ if (in != NULL) { if ((in_bio = BIO_new_file(in, "rb")) == NULL) goto end; if (token_in) { /* We have a ContentInfo (PKCS7) object, add 'granted' status info around it. */ response = read_PKCS7(in_bio); } else { /* We have a ready-made TS_RESP object. */ response = d2i_TS_RESP_bio(in_bio, NULL); } } else { response = create_response(conf, section, engine, queryfile, passin, inkey, signer, chain, policy); if (response) BIO_printf(bio_err, "Response has been generated.\n"); else BIO_printf(bio_err, "Response is not generated.\n"); } if (response == NULL) goto end; /* Write response either in ASN.1 or text format. */ if ((out_bio = BIO_open_with_default(out, "wb", stdout)) == NULL) goto end; if (text) { /* Text output. */ if (token_out) { TS_TST_INFO *tst_info = TS_RESP_get_tst_info(response); if (!TS_TST_INFO_print_bio(out_bio, tst_info)) goto end; } else { if (!TS_RESP_print_bio(out_bio, response)) goto end; } } else { /* ASN.1 DER output. */ if (token_out) { PKCS7 *token = TS_RESP_get_token(response); if (!i2d_PKCS7_bio(out_bio, token)) goto end; } else { if (!i2d_TS_RESP_bio(out_bio, response)) goto end; } } ret = 1; end: ERR_print_errors(bio_err); /* Clean up. */ BIO_free_all(in_bio); BIO_free_all(query_bio); BIO_free_all(inkey_bio); BIO_free_all(signer_bio); BIO_free_all(out_bio); TS_RESP_free(response); return ret; }
/* * Reply-related method definitions. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/ts.c#L673-L759
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
verify_command
static int verify_command(char *data, char *digest, char *queryfile, char *in, int token_in, char *ca_path, char *ca_file, char *untrusted) { BIO *in_bio = NULL; PKCS7 *token = NULL; TS_RESP *response = NULL; TS_VERIFY_CTX *verify_ctx = NULL; int ret = 0; /* Decode the token (PKCS7) or response (TS_RESP) files. */ if (!(in_bio = BIO_new_file(in, "rb"))) goto end; if (token_in) { if (!(token = d2i_PKCS7_bio(in_bio, NULL))) goto end; } else { if (!(response = d2i_TS_RESP_bio(in_bio, NULL))) goto end; } if (!(verify_ctx = create_verify_ctx(data, digest, queryfile, ca_path, ca_file, untrusted))) goto end; /* Checking the token or response against the request. */ ret = token_in ? TS_RESP_verify_token(verify_ctx, token) : TS_RESP_verify_response(verify_ctx, response); end: printf("Verification: "); if (ret) printf("OK\n"); else { printf("FAILED\n"); /* Print errors, if there are any. */ ERR_print_errors(bio_err); } /* Clean up. */ BIO_free_all(in_bio); PKCS7_free(token); TS_RESP_free(response); TS_VERIFY_CTX_free(verify_ctx); return ret; }
/* * Verify-related method definitions. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/ts.c#L961-L1008
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
if
else if (strcmp(*argv,"-crlext") == 0) { BIO_printf(bio_err,"use -clrext instead of -crlext\n"); clrext = 1; }
/* stay backwards-compatible with 0.9.5; this should go away soon */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/x509.c#L457-L461
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
sign
static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest, CONF *conf, char *section) { EVP_PKEY *pktmp; pktmp = X509_get_pubkey(x); EVP_PKEY_copy_parameters(pktmp,pkey); EVP_PKEY_save_parameters(pktmp,1); EVP_PKEY_free(pktmp); if (!X509_set_issuer_name(x,X509_get_subject_name(x))) goto err; if (X509_gmtime_adj(X509_get_notBefore(x),0) == NULL) goto err; /* Lets just make it 12:00am GMT, Jan 1 1970 */ /* memcpy(x->cert_info->validity->notBefore,"700101120000Z",13); */ /* 28 days to be certified */ if (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL) goto err; if (!X509_set_pubkey(x,pkey)) goto err; if (clrext) { while (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0); } if (conf) { X509V3_CTX ctx; X509_set_version(x,2); /* version 3 certificate */ X509V3_set_ctx(&ctx, x, x, NULL, NULL, 0); X509V3_set_nconf(&ctx, conf); if (!X509V3_EXT_add_nconf(conf, &ctx, section, x)) goto err; } if (!X509_sign(x,pkey,digest)) goto err; return 1; err: ERR_print_errors(bio_err); return 0; }
/* self sign */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/apps/x509.c#L1236-L1275
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
inc
void inc(a) int *a; { (*a)++; }
/* There is a bug in * gcc version 2.5.8 (88open OCS/BCS, DG-2.5.8.3, Oct 14 1994) * as shipped with DGUX 5.4R3.10 that can be bypassed by defining * DG_GCC_BUG in my code. * The bug manifests itself by the vaule of a pointer that is * used only by reference, not having it's value change when it is used * to check for exiting the loop. Probably caused by there being 2 * copies of the valiable, one in a register and one being an address * that is passed. */ /* compare the out put from * gcc dggccbug.c; ./a.out * and * gcc -O dggccbug.c; ./a.out * compile with -DFIXBUG to remove the bug when optimising. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/bugs/dggccbug.c#L24-L28
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
CRYPTO_THREADID_set_numeric
void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, unsigned long val) { memset(id, 0, sizeof(*id)); id->val = val; }
/* the memset() here and in set_pointer() seem overkill, but for the sake of * CRYPTO_THREADID_cmp() this avoids any platform silliness that might cause two * "equal" THREADID structs to not be memcmp()-identical. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/cryptlib.c#L424-L428
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
DllMain
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch(fdwReason) { case DLL_PROCESS_ATTACH: OPENSSL_cpuid_setup(); #if defined(_WIN32_WINNT) { IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)hinstDLL; IMAGE_NT_HEADERS *nt_headers; if (dos_header->e_magic==IMAGE_DOS_SIGNATURE) { nt_headers = (IMAGE_NT_HEADERS *)((char *)dos_header + dos_header->e_lfanew); if (nt_headers->Signature==IMAGE_NT_SIGNATURE && hinstDLL!=(HINSTANCE)(nt_headers->OptionalHeader.ImageBase)) OPENSSL_NONPIC_relocated=1; } } #endif break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: ERR_remove_state(0); break; case DLL_PROCESS_DETACH: break; } return(TRUE); }
/* All we really need to do is remove the 'error' state when a thread * detaches */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/cryptlib.c#L708-L740
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
impl_check
static void impl_check(void) { CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); if(!impl) impl = &impl_default; CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); }
/* Internal function that checks whether "impl" is set and if not, sets it to * the default. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L201-L207
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ex_class_item_hash
static unsigned long ex_class_item_hash(const EX_CLASS_ITEM *a) { return a->class_index; }
/* The callbacks required in the "ex_data" hash table */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L252-L255
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
def_cleanup_util_cb
static void def_cleanup_util_cb(CRYPTO_EX_DATA_FUNCS *funcs) { OPENSSL_free(funcs); }
/* This "inner" callback is used by the callback function that follows it */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L282-L285
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
def_cleanup_cb
static void def_cleanup_cb(void *a_void) { EX_CLASS_ITEM *item = (EX_CLASS_ITEM *)a_void; sk_CRYPTO_EX_DATA_FUNCS_pop_free(item->meth, def_cleanup_util_cb); OPENSSL_free(item); }
/* This callback is used in lh_doall to destroy all EX_CLASS_ITEM values from * "ex_data" prior to the ex_data hash table being itself destroyed. Doesn't do * any locking. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L290-L295
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
def_add_index
static int def_add_index(EX_CLASS_ITEM *item, long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) { int toret = -1; CRYPTO_EX_DATA_FUNCS *a = (CRYPTO_EX_DATA_FUNCS *)OPENSSL_malloc( sizeof(CRYPTO_EX_DATA_FUNCS)); if(!a) { CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX,ERR_R_MALLOC_FAILURE); return -1; } a->argl=argl; a->argp=argp; a->new_func=new_func; a->dup_func=dup_func; a->free_func=free_func; CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); while (sk_CRYPTO_EX_DATA_FUNCS_num(item->meth) <= item->meth_num) { if (!sk_CRYPTO_EX_DATA_FUNCS_push(item->meth, NULL)) { CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX,ERR_R_MALLOC_FAILURE); OPENSSL_free(a); goto err; } } toret = item->meth_num++; (void)sk_CRYPTO_EX_DATA_FUNCS_set(item->meth, toret, a); err: CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); return toret; }
/* Add a new method to the given EX_CLASS_ITEM and return the corresponding * index (or -1 for error). Handles locking. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L333-L365
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
int_new_class
static int int_new_class(void) { int toret; CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); toret = ex_class++; CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); return toret; }
/**************************************************************/ /* The functions in the default CRYPTO_EX_DATA_IMPL structure */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L370-L377
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
int_new_ex_data
static int int_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) { int mx,i; void *ptr; CRYPTO_EX_DATA_FUNCS **storage = NULL; EX_CLASS_ITEM *item = def_get_class(class_index); if(!item) /* error is already set */ return 0; ad->sk = NULL; CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA); mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth); if(mx > 0) { storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*)); if(!storage) goto skip; for(i = 0; i < mx; i++) storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth,i); } skip: CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); if((mx > 0) && !storage) { CRYPTOerr(CRYPTO_F_INT_NEW_EX_DATA,ERR_R_MALLOC_FAILURE); return 0; } for(i = 0; i < mx; i++) { if(storage[i] && storage[i]->new_func) { ptr = CRYPTO_get_ex_data(ad, i); storage[i]->new_func(obj,ptr,ad,i, storage[i]->argl,storage[i]->argp); } } if(storage) OPENSSL_free(storage); return 1; }
/* Thread-safe by copying a class's array of "CRYPTO_EX_DATA_FUNCS" entries in * the lock, then using them outside the lock. NB: Thread-safety only applies to * the global "ex_data" state (ie. class definitions), not thread-safe on 'ad' * itself. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L402-L442
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
int_dup_ex_data
static int int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from) { int mx, j, i; char *ptr; CRYPTO_EX_DATA_FUNCS **storage = NULL; EX_CLASS_ITEM *item; if(!from->sk) /* 'to' should be "blank" which *is* just like 'from' */ return 1; if((item = def_get_class(class_index)) == NULL) return 0; CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA); mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth); j = sk_void_num(from->sk); if(j < mx) mx = j; if(mx > 0) { storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*)); if(!storage) goto skip; for(i = 0; i < mx; i++) storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth,i); } skip: CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); if((mx > 0) && !storage) { CRYPTOerr(CRYPTO_F_INT_DUP_EX_DATA,ERR_R_MALLOC_FAILURE); return 0; } for(i = 0; i < mx; i++) { ptr = CRYPTO_get_ex_data(from, i); if(storage[i] && storage[i]->dup_func) storage[i]->dup_func(to,from,&ptr,i, storage[i]->argl,storage[i]->argp); CRYPTO_set_ex_data(to,i,ptr); } if(storage) OPENSSL_free(storage); return 1; }
/* Same thread-safety notes as for "int_new_ex_data" */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L445-L488
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
int_free_ex_data
static void int_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) { int mx,i; EX_CLASS_ITEM *item; void *ptr; CRYPTO_EX_DATA_FUNCS **storage = NULL; if((item = def_get_class(class_index)) == NULL) return; CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA); mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth); if(mx > 0) { storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*)); if(!storage) goto skip; for(i = 0; i < mx; i++) storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth,i); } skip: CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); if((mx > 0) && !storage) { CRYPTOerr(CRYPTO_F_INT_FREE_EX_DATA,ERR_R_MALLOC_FAILURE); return; } for(i = 0; i < mx; i++) { if(storage[i] && storage[i]->free_func) { ptr = CRYPTO_get_ex_data(ad,i); storage[i]->free_func(obj,ptr,ad,i, storage[i]->argl,storage[i]->argp); } } if(storage) OPENSSL_free(storage); if(ad->sk) { sk_void_free(ad->sk); ad->sk=NULL; } }
/* Same thread-safety notes as for "int_new_ex_data" */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L491-L533
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
CRYPTO_ex_data_new_class
int CRYPTO_ex_data_new_class(void) { IMPL_CHECK return EX_IMPL(new_class)(); }
/********************************************************************/ /* API functions that defer all "state" operations to the "ex_data" * implementation we have set. */ /* Obtain an index for a new class (not the same as getting a new index within * an existing class - this is actually getting a new *class*) */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L541-L545
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
CRYPTO_cleanup_all_ex_data
void CRYPTO_cleanup_all_ex_data(void) { IMPL_CHECK EX_IMPL(cleanup)(); }
/* Release all "ex_data" state to prevent memory leaks. This can't be made * thread-safe without overhauling a lot of stuff, and shouldn't really be * called under potential race-conditions anyway (it's for program shutdown * after all). */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L551-L555
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
CRYPTO_get_ex_new_index
int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) { int ret = -1; IMPL_CHECK ret = EX_IMPL(get_new_index)(class_index, argl, argp, new_func, dup_func, free_func); return ret; }
/* Inside an existing class, get/register a new index. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L558-L568
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
CRYPTO_new_ex_data
int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) { IMPL_CHECK return EX_IMPL(new_ex_data)(class_index, obj, ad); }
/* Initialise a new CRYPTO_EX_DATA for use in a particular class - including * calling new() callbacks for each index in the class used by this variable */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L572-L576
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
CRYPTO_dup_ex_data
int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from) { IMPL_CHECK return EX_IMPL(dup_ex_data)(class_index, to, from); }
/* Duplicate a CRYPTO_EX_DATA variable - including calling dup() callbacks for * each index in the class used by this variable */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L580-L585
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
CRYPTO_free_ex_data
void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) { IMPL_CHECK EX_IMPL(free_ex_data)(class_index, obj, ad); }
/* Cleanup a CRYPTO_EX_DATA variable - including calling free() callbacks for * each index in the class used by this variable */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L589-L593
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
CRYPTO_set_ex_data
int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val) { int i; if (ad->sk == NULL) { if ((ad->sk=sk_void_new_null()) == NULL) { CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE); return(0); } } i=sk_void_num(ad->sk); while (i <= idx) { if (!sk_void_push(ad->sk,NULL)) { CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA,ERR_R_MALLOC_FAILURE); return(0); } i++; } sk_void_set(ad->sk,idx,val); return(1); }
/* For a given CRYPTO_EX_DATA variable, set the value corresponding to a * particular index in the class used by this variable */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ex_data.c#L597-L622
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
date_to_julian
static long date_to_julian(int y, int m, int d) { return (1461 * (y + 4800 + (m - 14) / 12)) / 4 + (367 * (m - 2 - 12 * ((m - 14) / 12))) / 12 - (3 * ((y + 4900 + (m - 14) / 12) / 100)) / 4 + d - 32075; }
/* Convert date to and from julian day * Uses Fliegel & Van Flandern algorithm */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/o_time.c#L295-L301
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
main
int main(int argc, char **argv) { long offset; for (offset = 0; offset < 1000000; offset++) { check_time(offset); check_time(-offset); check_time(offset * 1000); check_time(-offset * 1000); } }
/* Time checking test code. Check times are identical for a wide range of * offsets. This should be run on a machine with 64 bit time_t or it will * trigger the very errors the routines fix. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/o_time.c#L328-L338
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_cfb128_encrypt
void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, const AES_KEY *key, unsigned char *ivec, int *num, const int enc) { CRYPTO_cfb128_encrypt(in,out,length,key,ivec,num,enc,(block128_f)AES_encrypt); }
/* The input and output encrypted as though 128bit cfb mode is being * used. The extra state information to record how much of the * 128bit block we have used is contained in *num; */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_cfb.c#L60-L65
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_cfb1_encrypt
void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, size_t length, const AES_KEY *key, unsigned char *ivec, int *num, const int enc) { CRYPTO_cfb128_1_encrypt(in,out,length,key,ivec,num,enc,(block128_f)AES_encrypt); }
/* N.B. This expects the input to be packed, MS bit first */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_cfb.c#L68-L73
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_set_encrypt_key
int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { u32 *rk; int i = 0; u32 temp; if (!userKey || !key) return -1; if (bits != 128 && bits != 192 && bits != 256) return -2; rk = key->rd_key; if (bits==128) key->rounds = 10; else if (bits==192) key->rounds = 12; else key->rounds = 14; rk[0] = GETU32(userKey ); rk[1] = GETU32(userKey + 4); rk[2] = GETU32(userKey + 8); rk[3] = GETU32(userKey + 12); if (bits == 128) { while (1) { temp = rk[3]; rk[4] = rk[0] ^ (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ (Te0[(temp ) & 0xff] & 0x0000ff00) ^ (Te1[(temp >> 24) ] & 0x000000ff) ^ rcon[i]; rk[5] = rk[1] ^ rk[4]; rk[6] = rk[2] ^ rk[5]; rk[7] = rk[3] ^ rk[6]; if (++i == 10) { return 0; } rk += 4; } } rk[4] = GETU32(userKey + 16); rk[5] = GETU32(userKey + 20); if (bits == 192) { while (1) { temp = rk[ 5]; rk[ 6] = rk[ 0] ^ (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ (Te0[(temp ) & 0xff] & 0x0000ff00) ^ (Te1[(temp >> 24) ] & 0x000000ff) ^ rcon[i]; rk[ 7] = rk[ 1] ^ rk[ 6]; rk[ 8] = rk[ 2] ^ rk[ 7]; rk[ 9] = rk[ 3] ^ rk[ 8]; if (++i == 8) { return 0; } rk[10] = rk[ 4] ^ rk[ 9]; rk[11] = rk[ 5] ^ rk[10]; rk += 6; } } rk[6] = GETU32(userKey + 24); rk[7] = GETU32(userKey + 28); if (bits == 256) { while (1) { temp = rk[ 7]; rk[ 8] = rk[ 0] ^ (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ (Te0[(temp ) & 0xff] & 0x0000ff00) ^ (Te1[(temp >> 24) ] & 0x000000ff) ^ rcon[i]; rk[ 9] = rk[ 1] ^ rk[ 8]; rk[10] = rk[ 2] ^ rk[ 9]; rk[11] = rk[ 3] ^ rk[10]; if (++i == 7) { return 0; } temp = rk[11]; rk[12] = rk[ 4] ^ (Te2[(temp >> 24) ] & 0xff000000) ^ (Te3[(temp >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(temp >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(temp ) & 0xff] & 0x000000ff); rk[13] = rk[ 5] ^ rk[12]; rk[14] = rk[ 6] ^ rk[13]; rk[15] = rk[ 7] ^ rk[14]; rk += 8; } } return 0; }
/** * Expand the cipher key into the encryption key schedule. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_core.c#L628-L724
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_set_decrypt_key
int AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { u32 *rk; int i, j, status; u32 temp; /* first, start with an encryption schedule */ status = AES_set_encrypt_key(userKey, bits, key); if (status < 0) return status; rk = key->rd_key; /* invert the order of the round keys: */ for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) { temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp; temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp; temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp; temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp; } /* apply the inverse MixColumn transform to all round keys but the first and the last: */ for (i = 1; i < (key->rounds); i++) { rk += 4; rk[0] = Td0[Te1[(rk[0] >> 24) ] & 0xff] ^ Td1[Te1[(rk[0] >> 16) & 0xff] & 0xff] ^ Td2[Te1[(rk[0] >> 8) & 0xff] & 0xff] ^ Td3[Te1[(rk[0] ) & 0xff] & 0xff]; rk[1] = Td0[Te1[(rk[1] >> 24) ] & 0xff] ^ Td1[Te1[(rk[1] >> 16) & 0xff] & 0xff] ^ Td2[Te1[(rk[1] >> 8) & 0xff] & 0xff] ^ Td3[Te1[(rk[1] ) & 0xff] & 0xff]; rk[2] = Td0[Te1[(rk[2] >> 24) ] & 0xff] ^ Td1[Te1[(rk[2] >> 16) & 0xff] & 0xff] ^ Td2[Te1[(rk[2] >> 8) & 0xff] & 0xff] ^ Td3[Te1[(rk[2] ) & 0xff] & 0xff]; rk[3] = Td0[Te1[(rk[3] >> 24) ] & 0xff] ^ Td1[Te1[(rk[3] >> 16) & 0xff] & 0xff] ^ Td2[Te1[(rk[3] >> 8) & 0xff] & 0xff] ^ Td3[Te1[(rk[3] ) & 0xff] & 0xff]; } return 0; }
/** * Expand the cipher key into the decryption key schedule. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_core.c#L729-L775
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_encrypt
void AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) { const u32 *rk; u32 s0, s1, s2, s3, t0, t1, t2, t3; #ifndef FULL_UNROLL int r; #endif /* ?FULL_UNROLL */ assert(in && out && key); rk = key->rd_key; /* * map byte array block to cipher state * and add initial round key: */ s0 = GETU32(in ) ^ rk[0]; s1 = GETU32(in + 4) ^ rk[1]; s2 = GETU32(in + 8) ^ rk[2]; s3 = GETU32(in + 12) ^ rk[3]; #ifdef FULL_UNROLL /* round 1: */ t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4]; t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5]; t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6]; t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7]; /* round 2: */ s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8]; s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9]; s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10]; s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11]; /* round 3: */ t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12]; t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13]; t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14]; t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15]; /* round 4: */ s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16]; s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17]; s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18]; s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19]; /* round 5: */ t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20]; t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21]; t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22]; t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23]; /* round 6: */ s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24]; s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25]; s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26]; s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27]; /* round 7: */ t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28]; t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29]; t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30]; t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31]; /* round 8: */ s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32]; s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33]; s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34]; s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35]; /* round 9: */ t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36]; t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37]; t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38]; t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39]; if (key->rounds > 10) { /* round 10: */ s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40]; s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41]; s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42]; s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43]; /* round 11: */ t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44]; t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45]; t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46]; t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47]; if (key->rounds > 12) { /* round 12: */ s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48]; s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49]; s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50]; s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51]; /* round 13: */ t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52]; t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53]; t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54]; t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55]; } } rk += key->rounds << 2; #else /* !FULL_UNROLL */ /* * Nr - 1 full rounds: */ r = key->rounds >> 1; for (;;) { t0 = Te0[(s0 >> 24) ] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[(s3 ) & 0xff] ^ rk[4]; t1 = Te0[(s1 >> 24) ] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[(s0 ) & 0xff] ^ rk[5]; t2 = Te0[(s2 >> 24) ] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[(s1 ) & 0xff] ^ rk[6]; t3 = Te0[(s3 >> 24) ] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[(s2 ) & 0xff] ^ rk[7]; rk += 8; if (--r == 0) { break; } s0 = Te0[(t0 >> 24) ] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[(t3 ) & 0xff] ^ rk[0]; s1 = Te0[(t1 >> 24) ] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[(t0 ) & 0xff] ^ rk[1]; s2 = Te0[(t2 >> 24) ] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[(t1 ) & 0xff] ^ rk[2]; s3 = Te0[(t3 >> 24) ] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[(t2 ) & 0xff] ^ rk[3]; } #endif /* ?FULL_UNROLL */ /* * apply last round and * map cipher state to byte array block: */ s0 = (Te2[(t0 >> 24) ] & 0xff000000) ^ (Te3[(t1 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t2 >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(t3 ) & 0xff] & 0x000000ff) ^ rk[0]; PUTU32(out , s0); s1 = (Te2[(t1 >> 24) ] & 0xff000000) ^ (Te3[(t2 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t3 >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(t0 ) & 0xff] & 0x000000ff) ^ rk[1]; PUTU32(out + 4, s1); s2 = (Te2[(t2 >> 24) ] & 0xff000000) ^ (Te3[(t3 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t0 >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(t1 ) & 0xff] & 0x000000ff) ^ rk[2]; PUTU32(out + 8, s2); s3 = (Te2[(t3 >> 24) ] & 0xff000000) ^ (Te3[(t0 >> 16) & 0xff] & 0x00ff0000) ^ (Te0[(t1 >> 8) & 0xff] & 0x0000ff00) ^ (Te1[(t2 ) & 0xff] & 0x000000ff) ^ rk[3]; PUTU32(out + 12, s3); }
/* * Encrypt a single block * in and out can overlap */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_core.c#L781-L966
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_decrypt
void AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) { const u32 *rk; u32 s0, s1, s2, s3, t0, t1, t2, t3; #ifndef FULL_UNROLL int r; #endif /* ?FULL_UNROLL */ assert(in && out && key); rk = key->rd_key; /* * map byte array block to cipher state * and add initial round key: */ s0 = GETU32(in ) ^ rk[0]; s1 = GETU32(in + 4) ^ rk[1]; s2 = GETU32(in + 8) ^ rk[2]; s3 = GETU32(in + 12) ^ rk[3]; #ifdef FULL_UNROLL /* round 1: */ t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[ 4]; t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[ 5]; t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[ 6]; t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[ 7]; /* round 2: */ s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[ 8]; s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[ 9]; s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[10]; s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[11]; /* round 3: */ t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[12]; t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[13]; t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[14]; t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[15]; /* round 4: */ s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[16]; s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[17]; s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[18]; s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[19]; /* round 5: */ t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[20]; t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[21]; t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[22]; t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[23]; /* round 6: */ s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[24]; s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[25]; s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[26]; s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[27]; /* round 7: */ t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[28]; t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[29]; t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[30]; t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[31]; /* round 8: */ s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[32]; s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[33]; s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[34]; s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[35]; /* round 9: */ t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[36]; t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[37]; t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[38]; t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[39]; if (key->rounds > 10) { /* round 10: */ s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[40]; s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[41]; s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[42]; s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[43]; /* round 11: */ t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[44]; t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[45]; t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[46]; t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[47]; if (key->rounds > 12) { /* round 12: */ s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[48]; s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[49]; s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[50]; s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[51]; /* round 13: */ t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[52]; t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[53]; t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[54]; t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[55]; } } rk += key->rounds << 2; #else /* !FULL_UNROLL */ /* * Nr - 1 full rounds: */ r = key->rounds >> 1; for (;;) { t0 = Td0[(s0 >> 24) ] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[(s1 ) & 0xff] ^ rk[4]; t1 = Td0[(s1 >> 24) ] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[(s2 ) & 0xff] ^ rk[5]; t2 = Td0[(s2 >> 24) ] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[(s3 ) & 0xff] ^ rk[6]; t3 = Td0[(s3 >> 24) ] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[(s0 ) & 0xff] ^ rk[7]; rk += 8; if (--r == 0) { break; } s0 = Td0[(t0 >> 24) ] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[(t1 ) & 0xff] ^ rk[0]; s1 = Td0[(t1 >> 24) ] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[(t2 ) & 0xff] ^ rk[1]; s2 = Td0[(t2 >> 24) ] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[(t3 ) & 0xff] ^ rk[2]; s3 = Td0[(t3 >> 24) ] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[(t0 ) & 0xff] ^ rk[3]; } #endif /* ?FULL_UNROLL */ /* * apply last round and * map cipher state to byte array block: */ s0 = (Td4[(t0 >> 24) ] << 24) ^ (Td4[(t3 >> 16) & 0xff] << 16) ^ (Td4[(t2 >> 8) & 0xff] << 8) ^ (Td4[(t1 ) & 0xff]) ^ rk[0]; PUTU32(out , s0); s1 = (Td4[(t1 >> 24) ] << 24) ^ (Td4[(t0 >> 16) & 0xff] << 16) ^ (Td4[(t3 >> 8) & 0xff] << 8) ^ (Td4[(t2 ) & 0xff]) ^ rk[1]; PUTU32(out + 4, s1); s2 = (Td4[(t2 >> 24) ] << 24) ^ (Td4[(t1 >> 16) & 0xff] << 16) ^ (Td4[(t0 >> 8) & 0xff] << 8) ^ (Td4[(t3 ) & 0xff]) ^ rk[2]; PUTU32(out + 8, s2); s3 = (Td4[(t3 >> 24) ] << 24) ^ (Td4[(t2 >> 16) & 0xff] << 16) ^ (Td4[(t1 >> 8) & 0xff] << 8) ^ (Td4[(t0 ) & 0xff]) ^ rk[3]; PUTU32(out + 12, s3); }
/* * Decrypt a single block * in and out can overlap */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_core.c#L972-L1157
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_set_encrypt_key
int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { u32 *rk; int i = 0; u32 temp; if (!userKey || !key) return -1; if (bits != 128 && bits != 192 && bits != 256) return -2; rk = key->rd_key; if (bits==128) key->rounds = 10; else if (bits==192) key->rounds = 12; else key->rounds = 14; rk[0] = GETU32(userKey ); rk[1] = GETU32(userKey + 4); rk[2] = GETU32(userKey + 8); rk[3] = GETU32(userKey + 12); if (bits == 128) { while (1) { temp = rk[3]; rk[4] = rk[0] ^ (Te4[(temp >> 16) & 0xff] << 24) ^ (Te4[(temp >> 8) & 0xff] << 16) ^ (Te4[(temp ) & 0xff] << 8) ^ (Te4[(temp >> 24) ]) ^ rcon[i]; rk[5] = rk[1] ^ rk[4]; rk[6] = rk[2] ^ rk[5]; rk[7] = rk[3] ^ rk[6]; if (++i == 10) { return 0; } rk += 4; } } rk[4] = GETU32(userKey + 16); rk[5] = GETU32(userKey + 20); if (bits == 192) { while (1) { temp = rk[ 5]; rk[ 6] = rk[ 0] ^ (Te4[(temp >> 16) & 0xff] << 24) ^ (Te4[(temp >> 8) & 0xff] << 16) ^ (Te4[(temp ) & 0xff] << 8) ^ (Te4[(temp >> 24) ]) ^ rcon[i]; rk[ 7] = rk[ 1] ^ rk[ 6]; rk[ 8] = rk[ 2] ^ rk[ 7]; rk[ 9] = rk[ 3] ^ rk[ 8]; if (++i == 8) { return 0; } rk[10] = rk[ 4] ^ rk[ 9]; rk[11] = rk[ 5] ^ rk[10]; rk += 6; } } rk[6] = GETU32(userKey + 24); rk[7] = GETU32(userKey + 28); if (bits == 256) { while (1) { temp = rk[ 7]; rk[ 8] = rk[ 0] ^ (Te4[(temp >> 16) & 0xff] << 24) ^ (Te4[(temp >> 8) & 0xff] << 16) ^ (Te4[(temp ) & 0xff] << 8) ^ (Te4[(temp >> 24) ]) ^ rcon[i]; rk[ 9] = rk[ 1] ^ rk[ 8]; rk[10] = rk[ 2] ^ rk[ 9]; rk[11] = rk[ 3] ^ rk[10]; if (++i == 7) { return 0; } temp = rk[11]; rk[12] = rk[ 4] ^ (Te4[(temp >> 24) ] << 24) ^ (Te4[(temp >> 16) & 0xff] << 16) ^ (Te4[(temp >> 8) & 0xff] << 8) ^ (Te4[(temp ) & 0xff]); rk[13] = rk[ 5] ^ rk[12]; rk[14] = rk[ 6] ^ rk[13]; rk[15] = rk[ 7] ^ rk[14]; rk += 8; } } return 0; }
/** * Expand the cipher key into the encryption key schedule. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_core.c#L1204-L1299
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_set_decrypt_key
int AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { u32 *rk; int i, j, status; u32 temp; /* first, start with an encryption schedule */ status = AES_set_encrypt_key(userKey, bits, key); if (status < 0) return status; rk = key->rd_key; /* invert the order of the round keys: */ for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) { temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp; temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp; temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp; temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp; } /* apply the inverse MixColumn transform to all round keys but the first and the last: */ for (i = 1; i < (key->rounds); i++) { rk += 4; for (j = 0; j < 4; j++) { u32 tp1, tp2, tp4, tp8, tp9, tpb, tpd, tpe, m; tp1 = rk[j]; m = tp1 & 0x80808080; tp2 = ((tp1 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); m = tp2 & 0x80808080; tp4 = ((tp2 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); m = tp4 & 0x80808080; tp8 = ((tp4 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); tp9 = tp8 ^ tp1; tpb = tp9 ^ tp2; tpd = tp9 ^ tp4; tpe = tp8 ^ tp4 ^ tp2; #if defined(ROTATE) rk[j] = tpe ^ ROTATE(tpd,16) ^ ROTATE(tp9,24) ^ ROTATE(tpb,8); #else rk[j] = tpe ^ (tpd >> 16) ^ (tpd << 16) ^ (tp9 >> 8) ^ (tp9 << 24) ^ (tpb >> 24) ^ (tpb << 8); #endif } } return 0; }
/** * Expand the cipher key into the decryption key schedule. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_core.c#L1304-L1356
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_ige_encrypt
void AES_ige_encrypt(const unsigned char *in, unsigned char *out, size_t length, const AES_KEY *key, unsigned char *ivec, const int enc) { size_t n; size_t len = length; OPENSSL_assert(in && out && key && ivec); OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); OPENSSL_assert((length%AES_BLOCK_SIZE) == 0); len = length / AES_BLOCK_SIZE; if (AES_ENCRYPT == enc) { if (in != out && (UNALIGNED_MEMOPS_ARE_FAST || ((size_t)in|(size_t)out|(size_t)ivec)%sizeof(long)==0)) { aes_block_t *ivp = (aes_block_t *)ivec; aes_block_t *iv2p = (aes_block_t *)(ivec + AES_BLOCK_SIZE); while (len) { aes_block_t *inp = (aes_block_t *)in; aes_block_t *outp = (aes_block_t *)out; for(n=0 ; n < N_WORDS; ++n) outp->data[n] = inp->data[n] ^ ivp->data[n]; AES_encrypt((unsigned char *)outp->data, (unsigned char *)outp->data, key); for(n=0 ; n < N_WORDS; ++n) outp->data[n] ^= iv2p->data[n]; ivp = outp; iv2p = inp; --len; in += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE; } memcpy(ivec, ivp->data, AES_BLOCK_SIZE); memcpy(ivec + AES_BLOCK_SIZE, iv2p->data, AES_BLOCK_SIZE); } else { aes_block_t tmp, tmp2; aes_block_t iv; aes_block_t iv2; load_block(iv, ivec); load_block(iv2, ivec + AES_BLOCK_SIZE); while (len) { load_block(tmp, in); for(n=0 ; n < N_WORDS; ++n) tmp2.data[n] = tmp.data[n] ^ iv.data[n]; AES_encrypt((unsigned char *)tmp2.data, (unsigned char *)tmp2.data, key); for(n=0 ; n < N_WORDS; ++n) tmp2.data[n] ^= iv2.data[n]; store_block(out, tmp2); iv = tmp2; iv2 = tmp; --len; in += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE; } memcpy(ivec, iv.data, AES_BLOCK_SIZE); memcpy(ivec + AES_BLOCK_SIZE, iv2.data, AES_BLOCK_SIZE); } } else { if (in != out && (UNALIGNED_MEMOPS_ARE_FAST || ((size_t)in|(size_t)out|(size_t)ivec)%sizeof(long)==0)) { aes_block_t *ivp = (aes_block_t *)ivec; aes_block_t *iv2p = (aes_block_t *)(ivec + AES_BLOCK_SIZE); while (len) { aes_block_t tmp; aes_block_t *inp = (aes_block_t *)in; aes_block_t *outp = (aes_block_t *)out; for(n=0 ; n < N_WORDS; ++n) tmp.data[n] = inp->data[n] ^ iv2p->data[n]; AES_decrypt((unsigned char *)tmp.data, (unsigned char *)outp->data, key); for(n=0 ; n < N_WORDS; ++n) outp->data[n] ^= ivp->data[n]; ivp = inp; iv2p = outp; --len; in += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE; } memcpy(ivec, ivp->data, AES_BLOCK_SIZE); memcpy(ivec + AES_BLOCK_SIZE, iv2p->data, AES_BLOCK_SIZE); } else { aes_block_t tmp, tmp2; aes_block_t iv; aes_block_t iv2; load_block(iv, ivec); load_block(iv2, ivec + AES_BLOCK_SIZE); while (len) { load_block(tmp, in); tmp2 = tmp; for(n=0 ; n < N_WORDS; ++n) tmp.data[n] ^= iv2.data[n]; AES_decrypt((unsigned char *)tmp.data, (unsigned char *)tmp.data, key); for(n=0 ; n < N_WORDS; ++n) tmp.data[n] ^= iv.data[n]; store_block(out, tmp); iv = tmp2; iv2 = tmp; --len; in += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE; } memcpy(ivec, iv.data, AES_BLOCK_SIZE); memcpy(ivec + AES_BLOCK_SIZE, iv2.data, AES_BLOCK_SIZE); } } }
/* N.B. The IV for this mode is _twice_ the block size */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_ige.c#L79-L204
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_bi_ige_encrypt
void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, size_t length, const AES_KEY *key, const AES_KEY *key2, const unsigned char *ivec, const int enc) { size_t n; size_t len = length; unsigned char tmp[AES_BLOCK_SIZE]; unsigned char tmp2[AES_BLOCK_SIZE]; unsigned char tmp3[AES_BLOCK_SIZE]; unsigned char prev[AES_BLOCK_SIZE]; const unsigned char *iv; const unsigned char *iv2; OPENSSL_assert(in && out && key && ivec); OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); OPENSSL_assert((length%AES_BLOCK_SIZE) == 0); if (AES_ENCRYPT == enc) { /* XXX: Do a separate case for when in != out (strictly should check for overlap, too) */ /* First the forward pass */ iv = ivec; iv2 = ivec + AES_BLOCK_SIZE; while (len >= AES_BLOCK_SIZE) { for(n=0 ; n < AES_BLOCK_SIZE ; ++n) out[n] = in[n] ^ iv[n]; AES_encrypt(out, out, key); for(n=0 ; n < AES_BLOCK_SIZE ; ++n) out[n] ^= iv2[n]; iv = out; memcpy(prev, in, AES_BLOCK_SIZE); iv2 = prev; len -= AES_BLOCK_SIZE; in += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE; } /* And now backwards */ iv = ivec + AES_BLOCK_SIZE*2; iv2 = ivec + AES_BLOCK_SIZE*3; len = length; while(len >= AES_BLOCK_SIZE) { out -= AES_BLOCK_SIZE; /* XXX: reduce copies by alternating between buffers */ memcpy(tmp, out, AES_BLOCK_SIZE); for(n=0 ; n < AES_BLOCK_SIZE ; ++n) out[n] ^= iv[n]; /* hexdump(stdout, "out ^ iv", out, AES_BLOCK_SIZE); */ AES_encrypt(out, out, key); /* hexdump(stdout,"enc", out, AES_BLOCK_SIZE); */ /* hexdump(stdout,"iv2", iv2, AES_BLOCK_SIZE); */ for(n=0 ; n < AES_BLOCK_SIZE ; ++n) out[n] ^= iv2[n]; /* hexdump(stdout,"out", out, AES_BLOCK_SIZE); */ iv = out; memcpy(prev, tmp, AES_BLOCK_SIZE); iv2 = prev; len -= AES_BLOCK_SIZE; } } else { /* First backwards */ iv = ivec + AES_BLOCK_SIZE*2; iv2 = ivec + AES_BLOCK_SIZE*3; in += length; out += length; while (len >= AES_BLOCK_SIZE) { in -= AES_BLOCK_SIZE; out -= AES_BLOCK_SIZE; memcpy(tmp, in, AES_BLOCK_SIZE); memcpy(tmp2, in, AES_BLOCK_SIZE); for(n=0 ; n < AES_BLOCK_SIZE ; ++n) tmp[n] ^= iv2[n]; AES_decrypt(tmp, out, key); for(n=0 ; n < AES_BLOCK_SIZE ; ++n) out[n] ^= iv[n]; memcpy(tmp3, tmp2, AES_BLOCK_SIZE); iv = tmp3; iv2 = out; len -= AES_BLOCK_SIZE; } /* And now forwards */ iv = ivec; iv2 = ivec + AES_BLOCK_SIZE; len = length; while (len >= AES_BLOCK_SIZE) { memcpy(tmp, out, AES_BLOCK_SIZE); memcpy(tmp2, out, AES_BLOCK_SIZE); for(n=0 ; n < AES_BLOCK_SIZE ; ++n) tmp[n] ^= iv2[n]; AES_decrypt(tmp, out, key); for(n=0 ; n < AES_BLOCK_SIZE ; ++n) out[n] ^= iv[n]; memcpy(tmp3, tmp2, AES_BLOCK_SIZE); iv = tmp3; iv2 = out; len -= AES_BLOCK_SIZE; in += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE; } } }
/* * Note that its effectively impossible to do biIGE in anything other * than a single pass, so no provision is made for chaining. */ /* N.B. The IV for this mode is _four times_ the block size */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_ige.c#L213-L323
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_set_encrypt_key
int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { u32 *rk; int i = 0; u32 temp; if (!userKey || !key) return -1; if (bits != 128 && bits != 192 && bits != 256) return -2; rk = key->rd_key; if (bits==128) key->rounds = 10; else if (bits==192) key->rounds = 12; else key->rounds = 14; rk[0] = GETU32(userKey ); rk[1] = GETU32(userKey + 4); rk[2] = GETU32(userKey + 8); rk[3] = GETU32(userKey + 12); if (bits == 128) { while (1) { temp = rk[3]; rk[4] = rk[0] ^ (Te4[(temp >> 8) & 0xff] ) ^ (Te4[(temp >> 16) & 0xff] << 8) ^ (Te4[(temp >> 24) ] << 16) ^ (Te4[(temp ) & 0xff] << 24) ^ rcon[i]; rk[5] = rk[1] ^ rk[4]; rk[6] = rk[2] ^ rk[5]; rk[7] = rk[3] ^ rk[6]; if (++i == 10) { return 0; } rk += 4; } } rk[4] = GETU32(userKey + 16); rk[5] = GETU32(userKey + 20); if (bits == 192) { while (1) { temp = rk[ 5]; rk[ 6] = rk[ 0] ^ (Te4[(temp >> 8) & 0xff] ) ^ (Te4[(temp >> 16) & 0xff] << 8) ^ (Te4[(temp >> 24) ] << 16) ^ (Te4[(temp ) & 0xff] << 24) ^ rcon[i]; rk[ 7] = rk[ 1] ^ rk[ 6]; rk[ 8] = rk[ 2] ^ rk[ 7]; rk[ 9] = rk[ 3] ^ rk[ 8]; if (++i == 8) { return 0; } rk[10] = rk[ 4] ^ rk[ 9]; rk[11] = rk[ 5] ^ rk[10]; rk += 6; } } rk[6] = GETU32(userKey + 24); rk[7] = GETU32(userKey + 28); if (bits == 256) { while (1) { temp = rk[ 7]; rk[ 8] = rk[ 0] ^ (Te4[(temp >> 8) & 0xff] ) ^ (Te4[(temp >> 16) & 0xff] << 8) ^ (Te4[(temp >> 24) ] << 16) ^ (Te4[(temp ) & 0xff] << 24) ^ rcon[i]; rk[ 9] = rk[ 1] ^ rk[ 8]; rk[10] = rk[ 2] ^ rk[ 9]; rk[11] = rk[ 3] ^ rk[10]; if (++i == 7) { return 0; } temp = rk[11]; rk[12] = rk[ 4] ^ (Te4[(temp ) & 0xff] ) ^ (Te4[(temp >> 8) & 0xff] << 8) ^ (Te4[(temp >> 16) & 0xff] << 16) ^ (Te4[(temp >> 24) ] << 24); rk[13] = rk[ 5] ^ rk[12]; rk[14] = rk[ 6] ^ rk[13]; rk[15] = rk[ 7] ^ rk[14]; rk += 8; } } return 0; }
/** * Expand the cipher key into the encryption key schedule. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_x86core.c#L470-L566
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_set_decrypt_key
int AES_set_decrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key) { u32 *rk; int i, j, status; u32 temp; /* first, start with an encryption schedule */ status = AES_set_encrypt_key(userKey, bits, key); if (status < 0) return status; rk = key->rd_key; /* invert the order of the round keys: */ for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) { temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp; temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp; temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp; temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp; } /* apply the inverse MixColumn transform to all round keys but the first and the last: */ for (i = 1; i < (key->rounds); i++) { rk += 4; #if 1 for (j = 0; j < 4; j++) { u32 tp1, tp2, tp4, tp8, tp9, tpb, tpd, tpe, m; tp1 = rk[j]; m = tp1 & 0x80808080; tp2 = ((tp1 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); m = tp2 & 0x80808080; tp4 = ((tp2 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); m = tp4 & 0x80808080; tp8 = ((tp4 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); tp9 = tp8 ^ tp1; tpb = tp9 ^ tp2; tpd = tp9 ^ tp4; tpe = tp8 ^ tp4 ^ tp2; #if defined(ROTATE) rk[j] = tpe ^ ROTATE(tpd,16) ^ ROTATE(tp9,8) ^ ROTATE(tpb,24); #else rk[j] = tpe ^ (tpd >> 16) ^ (tpd << 16) ^ (tp9 >> 24) ^ (tp9 << 8) ^ (tpb >> 8) ^ (tpb << 24); #endif } #else rk[0] = Td0[Te2[(rk[0] ) & 0xff] & 0xff] ^ Td1[Te2[(rk[0] >> 8) & 0xff] & 0xff] ^ Td2[Te2[(rk[0] >> 16) & 0xff] & 0xff] ^ Td3[Te2[(rk[0] >> 24) ] & 0xff]; rk[1] = Td0[Te2[(rk[1] ) & 0xff] & 0xff] ^ Td1[Te2[(rk[1] >> 8) & 0xff] & 0xff] ^ Td2[Te2[(rk[1] >> 16) & 0xff] & 0xff] ^ Td3[Te2[(rk[1] >> 24) ] & 0xff]; rk[2] = Td0[Te2[(rk[2] ) & 0xff] & 0xff] ^ Td1[Te2[(rk[2] >> 8) & 0xff] & 0xff] ^ Td2[Te2[(rk[2] >> 16) & 0xff] & 0xff] ^ Td3[Te2[(rk[2] >> 24) ] & 0xff]; rk[3] = Td0[Te2[(rk[3] ) & 0xff] & 0xff] ^ Td1[Te2[(rk[3] >> 8) & 0xff] & 0xff] ^ Td2[Te2[(rk[3] >> 16) & 0xff] & 0xff] ^ Td3[Te2[(rk[3] >> 24) ] & 0xff]; #endif } return 0; }
/** * Expand the cipher key into the decryption key schedule. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_x86core.c#L571-L646
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_encrypt
void AES_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) { const u32 *rk; u32 s0, s1, s2, s3, t[4]; int r; assert(in && out && key); rk = key->rd_key; /* * map byte array block to cipher state * and add initial round key: */ s0 = GETU32(in ) ^ rk[0]; s1 = GETU32(in + 4) ^ rk[1]; s2 = GETU32(in + 8) ^ rk[2]; s3 = GETU32(in + 12) ^ rk[3]; #if defined(AES_COMPACT_IN_OUTER_ROUNDS) prefetch256(Te4); t[0] = Te4[(s0 ) & 0xff] ^ Te4[(s1 >> 8) & 0xff] << 8 ^ Te4[(s2 >> 16) & 0xff] << 16 ^ Te4[(s3 >> 24) ] << 24; t[1] = Te4[(s1 ) & 0xff] ^ Te4[(s2 >> 8) & 0xff] << 8 ^ Te4[(s3 >> 16) & 0xff] << 16 ^ Te4[(s0 >> 24) ] << 24; t[2] = Te4[(s2 ) & 0xff] ^ Te4[(s3 >> 8) & 0xff] << 8 ^ Te4[(s0 >> 16) & 0xff] << 16 ^ Te4[(s1 >> 24) ] << 24; t[3] = Te4[(s3 ) & 0xff] ^ Te4[(s0 >> 8) & 0xff] << 8 ^ Te4[(s1 >> 16) & 0xff] << 16 ^ Te4[(s2 >> 24) ] << 24; /* now do the linear transform using words */ { int i; u32 r0, r1, r2; for (i = 0; i < 4; i++) { r0 = t[i]; r1 = r0 & 0x80808080; r2 = ((r0 & 0x7f7f7f7f) << 1) ^ ((r1 - (r1 >> 7)) & 0x1b1b1b1b); #if defined(ROTATE) t[i] = r2 ^ ROTATE(r2,24) ^ ROTATE(r0,24) ^ ROTATE(r0,16) ^ ROTATE(r0,8); #else t[i] = r2 ^ ((r2 ^ r0) << 24) ^ ((r2 ^ r0) >> 8) ^ (r0 << 16) ^ (r0 >> 16) ^ (r0 << 8) ^ (r0 >> 24); #endif t[i] ^= rk[4+i]; } } #else t[0] = Te0[(s0 ) & 0xff] ^ Te1[(s1 >> 8) & 0xff] ^ Te2[(s2 >> 16) & 0xff] ^ Te3[(s3 >> 24) ] ^ rk[4]; t[1] = Te0[(s1 ) & 0xff] ^ Te1[(s2 >> 8) & 0xff] ^ Te2[(s3 >> 16) & 0xff] ^ Te3[(s0 >> 24) ] ^ rk[5]; t[2] = Te0[(s2 ) & 0xff] ^ Te1[(s3 >> 8) & 0xff] ^ Te2[(s0 >> 16) & 0xff] ^ Te3[(s1 >> 24) ] ^ rk[6]; t[3] = Te0[(s3 ) & 0xff] ^ Te1[(s0 >> 8) & 0xff] ^ Te2[(s1 >> 16) & 0xff] ^ Te3[(s2 >> 24) ] ^ rk[7]; #endif s0 = t[0]; s1 = t[1]; s2 = t[2]; s3 = t[3]; /* * Nr - 2 full rounds: */ for (rk+=8,r=key->rounds-2; r>0; rk+=4,r--) { #if defined(AES_COMPACT_IN_INNER_ROUNDS) t[0] = Te4[(s0 ) & 0xff] ^ Te4[(s1 >> 8) & 0xff] << 8 ^ Te4[(s2 >> 16) & 0xff] << 16 ^ Te4[(s3 >> 24) ] << 24; t[1] = Te4[(s1 ) & 0xff] ^ Te4[(s2 >> 8) & 0xff] << 8 ^ Te4[(s3 >> 16) & 0xff] << 16 ^ Te4[(s0 >> 24) ] << 24; t[2] = Te4[(s2 ) & 0xff] ^ Te4[(s3 >> 8) & 0xff] << 8 ^ Te4[(s0 >> 16) & 0xff] << 16 ^ Te4[(s1 >> 24) ] << 24; t[3] = Te4[(s3 ) & 0xff] ^ Te4[(s0 >> 8) & 0xff] << 8 ^ Te4[(s1 >> 16) & 0xff] << 16 ^ Te4[(s2 >> 24) ] << 24; /* now do the linear transform using words */ { int i; u32 r0, r1, r2; for (i = 0; i < 4; i++) { r0 = t[i]; r1 = r0 & 0x80808080; r2 = ((r0 & 0x7f7f7f7f) << 1) ^ ((r1 - (r1 >> 7)) & 0x1b1b1b1b); #if defined(ROTATE) t[i] = r2 ^ ROTATE(r2,24) ^ ROTATE(r0,24) ^ ROTATE(r0,16) ^ ROTATE(r0,8); #else t[i] = r2 ^ ((r2 ^ r0) << 24) ^ ((r2 ^ r0) >> 8) ^ (r0 << 16) ^ (r0 >> 16) ^ (r0 << 8) ^ (r0 >> 24); #endif t[i] ^= rk[i]; } } #else t[0] = Te0[(s0 ) & 0xff] ^ Te1[(s1 >> 8) & 0xff] ^ Te2[(s2 >> 16) & 0xff] ^ Te3[(s3 >> 24) ] ^ rk[0]; t[1] = Te0[(s1 ) & 0xff] ^ Te1[(s2 >> 8) & 0xff] ^ Te2[(s3 >> 16) & 0xff] ^ Te3[(s0 >> 24) ] ^ rk[1]; t[2] = Te0[(s2 ) & 0xff] ^ Te1[(s3 >> 8) & 0xff] ^ Te2[(s0 >> 16) & 0xff] ^ Te3[(s1 >> 24) ] ^ rk[2]; t[3] = Te0[(s3 ) & 0xff] ^ Te1[(s0 >> 8) & 0xff] ^ Te2[(s1 >> 16) & 0xff] ^ Te3[(s2 >> 24) ] ^ rk[3]; #endif s0 = t[0]; s1 = t[1]; s2 = t[2]; s3 = t[3]; } /* * apply last round and * map cipher state to byte array block: */ #if defined(AES_COMPACT_IN_OUTER_ROUNDS) prefetch256(Te4); *(u32*)(out+0) = Te4[(s0 ) & 0xff] ^ Te4[(s1 >> 8) & 0xff] << 8 ^ Te4[(s2 >> 16) & 0xff] << 16 ^ Te4[(s3 >> 24) ] << 24 ^ rk[0]; *(u32*)(out+4) = Te4[(s1 ) & 0xff] ^ Te4[(s2 >> 8) & 0xff] << 8 ^ Te4[(s3 >> 16) & 0xff] << 16 ^ Te4[(s0 >> 24) ] << 24 ^ rk[1]; *(u32*)(out+8) = Te4[(s2 ) & 0xff] ^ Te4[(s3 >> 8) & 0xff] << 8 ^ Te4[(s0 >> 16) & 0xff] << 16 ^ Te4[(s1 >> 24) ] << 24 ^ rk[2]; *(u32*)(out+12) = Te4[(s3 ) & 0xff] ^ Te4[(s0 >> 8) & 0xff] << 8 ^ Te4[(s1 >> 16) & 0xff] << 16 ^ Te4[(s2 >> 24) ] << 24 ^ rk[3]; #else *(u32*)(out+0) = (Te2[(s0 ) & 0xff] & 0x000000ffU) ^ (Te3[(s1 >> 8) & 0xff] & 0x0000ff00U) ^ (Te0[(s2 >> 16) & 0xff] & 0x00ff0000U) ^ (Te1[(s3 >> 24) ] & 0xff000000U) ^ rk[0]; *(u32*)(out+4) = (Te2[(s1 ) & 0xff] & 0x000000ffU) ^ (Te3[(s2 >> 8) & 0xff] & 0x0000ff00U) ^ (Te0[(s3 >> 16) & 0xff] & 0x00ff0000U) ^ (Te1[(s0 >> 24) ] & 0xff000000U) ^ rk[1]; *(u32*)(out+8) = (Te2[(s2 ) & 0xff] & 0x000000ffU) ^ (Te3[(s3 >> 8) & 0xff] & 0x0000ff00U) ^ (Te0[(s0 >> 16) & 0xff] & 0x00ff0000U) ^ (Te1[(s1 >> 24) ] & 0xff000000U) ^ rk[2]; *(u32*)(out+12) = (Te2[(s3 ) & 0xff] & 0x000000ffU) ^ (Te3[(s0 >> 8) & 0xff] & 0x0000ff00U) ^ (Te0[(s1 >> 16) & 0xff] & 0x00ff0000U) ^ (Te1[(s2 >> 24) ] & 0xff000000U) ^ rk[3]; #endif }
/* * Encrypt a single block * in and out can overlap */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_x86core.c#L652-L858
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
AES_decrypt
void AES_decrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key) { const u32 *rk; u32 s0, s1, s2, s3, t[4]; int r; assert(in && out && key); rk = key->rd_key; /* * map byte array block to cipher state * and add initial round key: */ s0 = GETU32(in ) ^ rk[0]; s1 = GETU32(in + 4) ^ rk[1]; s2 = GETU32(in + 8) ^ rk[2]; s3 = GETU32(in + 12) ^ rk[3]; #if defined(AES_COMPACT_IN_OUTER_ROUNDS) prefetch256(Td4); t[0] = Td4[(s0 ) & 0xff] ^ Td4[(s3 >> 8) & 0xff] << 8 ^ Td4[(s2 >> 16) & 0xff] << 16 ^ Td4[(s1 >> 24) ] << 24; t[1] = Td4[(s1 ) & 0xff] ^ Td4[(s0 >> 8) & 0xff] << 8 ^ Td4[(s3 >> 16) & 0xff] << 16 ^ Td4[(s2 >> 24) ] << 24; t[2] = Td4[(s2 ) & 0xff] ^ Td4[(s1 >> 8) & 0xff] << 8 ^ Td4[(s0 >> 16) & 0xff] << 16 ^ Td4[(s3 >> 24) ] << 24; t[3] = Td4[(s3 ) & 0xff] ^ Td4[(s2 >> 8) & 0xff] << 8 ^ Td4[(s1 >> 16) & 0xff] << 16 ^ Td4[(s0 >> 24) ] << 24; /* now do the linear transform using words */ { int i; u32 tp1, tp2, tp4, tp8, tp9, tpb, tpd, tpe, m; for (i = 0; i < 4; i++) { tp1 = t[i]; m = tp1 & 0x80808080; tp2 = ((tp1 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); m = tp2 & 0x80808080; tp4 = ((tp2 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); m = tp4 & 0x80808080; tp8 = ((tp4 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); tp9 = tp8 ^ tp1; tpb = tp9 ^ tp2; tpd = tp9 ^ tp4; tpe = tp8 ^ tp4 ^ tp2; #if defined(ROTATE) t[i] = tpe ^ ROTATE(tpd,16) ^ ROTATE(tp9,8) ^ ROTATE(tpb,24); #else t[i] = tpe ^ (tpd >> 16) ^ (tpd << 16) ^ (tp9 >> 24) ^ (tp9 << 8) ^ (tpb >> 8) ^ (tpb << 24); #endif t[i] ^= rk[4+i]; } } #else t[0] = Td0[(s0 ) & 0xff] ^ Td1[(s3 >> 8) & 0xff] ^ Td2[(s2 >> 16) & 0xff] ^ Td3[(s1 >> 24) ] ^ rk[4]; t[1] = Td0[(s1 ) & 0xff] ^ Td1[(s0 >> 8) & 0xff] ^ Td2[(s3 >> 16) & 0xff] ^ Td3[(s2 >> 24) ] ^ rk[5]; t[2] = Td0[(s2 ) & 0xff] ^ Td1[(s1 >> 8) & 0xff] ^ Td2[(s0 >> 16) & 0xff] ^ Td3[(s3 >> 24) ] ^ rk[6]; t[3] = Td0[(s3 ) & 0xff] ^ Td1[(s2 >> 8) & 0xff] ^ Td2[(s1 >> 16) & 0xff] ^ Td3[(s0 >> 24) ] ^ rk[7]; #endif s0 = t[0]; s1 = t[1]; s2 = t[2]; s3 = t[3]; /* * Nr - 2 full rounds: */ for (rk+=8,r=key->rounds-2; r>0; rk+=4,r--) { #if defined(AES_COMPACT_IN_INNER_ROUNDS) t[0] = Td4[(s0 ) & 0xff] ^ Td4[(s3 >> 8) & 0xff] << 8 ^ Td4[(s2 >> 16) & 0xff] << 16 ^ Td4[(s1 >> 24) ] << 24; t[1] = Td4[(s1 ) & 0xff] ^ Td4[(s0 >> 8) & 0xff] << 8 ^ Td4[(s3 >> 16) & 0xff] << 16 ^ Td4[(s2 >> 24) ] << 24; t[2] = Td4[(s2 ) & 0xff] ^ Td4[(s1 >> 8) & 0xff] << 8 ^ Td4[(s0 >> 16) & 0xff] << 16 ^ Td4[(s3 >> 24) ] << 24; t[3] = Td4[(s3 ) & 0xff] ^ Td4[(s2 >> 8) & 0xff] << 8 ^ Td4[(s1 >> 16) & 0xff] << 16 ^ Td4[(s0 >> 24) ] << 24; /* now do the linear transform using words */ { int i; u32 tp1, tp2, tp4, tp8, tp9, tpb, tpd, tpe, m; for (i = 0; i < 4; i++) { tp1 = t[i]; m = tp1 & 0x80808080; tp2 = ((tp1 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); m = tp2 & 0x80808080; tp4 = ((tp2 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); m = tp4 & 0x80808080; tp8 = ((tp4 & 0x7f7f7f7f) << 1) ^ ((m - (m >> 7)) & 0x1b1b1b1b); tp9 = tp8 ^ tp1; tpb = tp9 ^ tp2; tpd = tp9 ^ tp4; tpe = tp8 ^ tp4 ^ tp2; #if defined(ROTATE) t[i] = tpe ^ ROTATE(tpd,16) ^ ROTATE(tp9,8) ^ ROTATE(tpb,24); #else t[i] = tpe ^ (tpd >> 16) ^ (tpd << 16) ^ (tp9 >> 24) ^ (tp9 << 8) ^ (tpb >> 8) ^ (tpb << 24); #endif t[i] ^= rk[i]; } } #else t[0] = Td0[(s0 ) & 0xff] ^ Td1[(s3 >> 8) & 0xff] ^ Td2[(s2 >> 16) & 0xff] ^ Td3[(s1 >> 24) ] ^ rk[0]; t[1] = Td0[(s1 ) & 0xff] ^ Td1[(s0 >> 8) & 0xff] ^ Td2[(s3 >> 16) & 0xff] ^ Td3[(s2 >> 24) ] ^ rk[1]; t[2] = Td0[(s2 ) & 0xff] ^ Td1[(s1 >> 8) & 0xff] ^ Td2[(s0 >> 16) & 0xff] ^ Td3[(s3 >> 24) ] ^ rk[2]; t[3] = Td0[(s3 ) & 0xff] ^ Td1[(s2 >> 8) & 0xff] ^ Td2[(s1 >> 16) & 0xff] ^ Td3[(s0 >> 24) ] ^ rk[3]; #endif s0 = t[0]; s1 = t[1]; s2 = t[2]; s3 = t[3]; } /* * apply last round and * map cipher state to byte array block: */ prefetch256(Td4); *(u32*)(out+0) = (Td4[(s0 ) & 0xff]) ^ (Td4[(s3 >> 8) & 0xff] << 8) ^ (Td4[(s2 >> 16) & 0xff] << 16) ^ (Td4[(s1 >> 24) ] << 24) ^ rk[0]; *(u32*)(out+4) = (Td4[(s1 ) & 0xff]) ^ (Td4[(s0 >> 8) & 0xff] << 8) ^ (Td4[(s3 >> 16) & 0xff] << 16) ^ (Td4[(s2 >> 24) ] << 24) ^ rk[1]; *(u32*)(out+8) = (Td4[(s2 ) & 0xff]) ^ (Td4[(s1 >> 8) & 0xff] << 8) ^ (Td4[(s0 >> 16) & 0xff] << 16) ^ (Td4[(s3 >> 24) ] << 24) ^ rk[2]; *(u32*)(out+12) = (Td4[(s3 ) & 0xff]) ^ (Td4[(s2 >> 8) & 0xff] << 8) ^ (Td4[(s1 >> 16) & 0xff] << 16) ^ (Td4[(s0 >> 24) ] << 24) ^ rk[3]; }
/* * Decrypt a single block * in and out can overlap */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/aes/aes_x86core.c#L864-L1063
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_BIT_STRING_set_bit
int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) { int w,v,iv; unsigned char *c; w=n/8; v=1<<(7-(n&0x07)); iv= ~v; if (!value) v=0; if (a == NULL) return 0; a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ if ((a->length < (w+1)) || (a->data == NULL)) { if (!value) return(1); /* Don't need to set */ if (a->data == NULL) c=(unsigned char *)OPENSSL_malloc(w+1); else c=(unsigned char *)OPENSSL_realloc_clean(a->data, a->length, w+1); if (c == NULL) { ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT,ERR_R_MALLOC_FAILURE); return 0; } if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length); a->data=c; a->length=w+1; } a->data[w]=((a->data[w])&iv)|v; while ((a->length > 0) && (a->data[a->length-1] == 0)) a->length--; return(1); }
/* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_bitstr.c#L176-L213
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_BIT_STRING_check
int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, unsigned char *flags, int flags_len) { int i, ok; /* Check if there is one bit set at all. */ if (!a || !a->data) return 1; /* Check each byte of the internal representation of the bit string. */ ok = 1; for (i = 0; i < a->length && ok; ++i) { unsigned char mask = i < flags_len ? ~flags[i] : 0xff; /* We are done if there is an unneeded bit set. */ ok = (a->data[i] & mask) == 0; } return ok; }
/* * Checks if the given bit string contains only bits specified by * the flags vector. Returns 0 if there is at least one bit set in 'a' * which is not specified in 'flags', 1 otherwise. * 'len' is the length of 'flags'. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_bitstr.c#L232-L248
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
asn1_collate_primitive
static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c) { ASN1_STRING *os=NULL; BUF_MEM b; int num; b.length=0; b.max=0; b.data=NULL; if (a == NULL) { c->error=ERR_R_PASSED_NULL_PARAMETER; goto err; } num=0; for (;;) { if (c->inf & 1) { c->eos=ASN1_const_check_infinite_end(&c->p, (long)(c->max-c->p)); if (c->eos) break; } else { if (c->slen <= 0) break; } c->q=c->p; if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass) == NULL) { c->error=ERR_R_ASN1_LIB; goto err; } if (!BUF_MEM_grow_clean(&b,num+os->length)) { c->error=ERR_R_BUF_LIB; goto err; } memcpy(&(b.data[num]),os->data,os->length); if (!(c->inf & 1)) c->slen-=(c->p-c->q); num+=os->length; } if (!asn1_const_Finish(c)) goto err; a->length=num; if (a->data != NULL) OPENSSL_free(a->data); a->data=(unsigned char *)b.data; if (os != NULL) ASN1_STRING_free(os); return(1); err: ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error); if (os != NULL) ASN1_STRING_free(os); if (b.data != NULL) OPENSSL_free(b.data); return(0); }
/* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse * them into the one structure that is then returned */ /* There have been a few bug fixes for this function from * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_bytes.c#L252-L313
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_ENUMERATED_set
int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) { int j,k; unsigned int i; unsigned char buf[sizeof(long)+1]; long d; a->type=V_ASN1_ENUMERATED; if (a->length < (int)(sizeof(long)+1)) { if (a->data != NULL) OPENSSL_free(a->data); if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL) memset((char *)a->data,0,sizeof(long)+1); } if (a->data == NULL) { ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); return(0); } d=v; if (d < 0) { d= -d; a->type=V_ASN1_NEG_ENUMERATED; } for (i=0; i<sizeof(long); i++) { if (d == 0) break; buf[i]=(int)d&0xff; d>>=8; } j=0; for (k=i-1; k >=0; k--) a->data[j++]=buf[k]; a->length=j; return(1); }
/* * Code for ENUMERATED type: identical to INTEGER apart from a different tag. * for comments on encoding see a_int.c */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_enum.c#L69-L107
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
i2c_ASN1_INTEGER
int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) { int pad=0,ret,i,neg; unsigned char *p,*n,pb=0; if ((a == NULL) || (a->data == NULL)) return(0); neg=a->type & V_ASN1_NEG; if (a->length == 0) ret=1; else { ret=a->length; i=a->data[0]; if (!neg && (i > 127)) { pad=1; pb=0; } else if(neg) { if(i>128) { pad=1; pb=0xFF; } else if(i == 128) { /* * Special case: if any other bytes non zero we pad: * otherwise we don't. */ for(i = 1; i < a->length; i++) if(a->data[i]) { pad=1; pb=0xFF; break; } } } ret+=pad; } if (pp == NULL) return(ret); p= *pp; if (pad) *(p++)=pb; if (a->length == 0) *(p++)=0; else if (!neg) memcpy(p,a->data,(unsigned int)a->length); else { /* Begin at the end of the encoding */ n=a->data + a->length - 1; p += a->length - 1; i = a->length; /* Copy zeros to destination as long as source is zero */ while(!*n) { *(p--) = 0; n--; i--; } /* Complement and increment next octet */ *(p--) = ((*(n--)) ^ 0xff) + 1; i--; /* Complement any octets left */ for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; } *pp+=ret; return(ret); }
/* * This converts an ASN1 INTEGER into its content encoding. * The internal representation is an ASN1_STRING whose data is a big endian * representation of the value, ignoring the sign. The sign is determined by * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative. * * Positive integers are no problem: they are almost the same as the DER * encoding, except if the first byte is >= 0x80 we need to add a zero pad. * * Negative integers are a bit trickier... * The DER representation of negative integers is in 2s complement form. * The internal form is converted by complementing each octet and finally * adding one to the result. This can be done less messily with a little trick. * If the internal form has trailing zeroes then they will become FF by the * complement and 0 by the add one (due to carry) so just copy as many trailing * zeros to the destination as there are in the source. The carry will add one * to the last none zero octet: so complement this octet and add one and finally * complement any left over until you get to the start of the string. * * Padding is a little trickier too. If the first bytes is > 0x80 then we pad * with 0xff. However if the first byte is 0x80 and one of the following bytes * is non-zero we pad with 0xff. The reason for this distinction is that 0x80 * followed by optional zeros isn't padded. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_int.c#L114-L174
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_mbstring_copy
int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, int inform, unsigned long mask) { return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0); }
/* These functions take a string in UTF8, ASCII or multibyte form and * a mask of permissible ASN1 string types. It then works out the minimal * type (using the order Printable < IA5 < T61 < BMP < Universal < UTF8) * and creates a string of the correct type with the supplied data. * Yes this is horrible: it has to be :-( * The 'ncopy' form checks minimum and maximum size limits too. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L83-L87
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
traverse_string
static int traverse_string(const unsigned char *p, int len, int inform, int (*rfunc)(unsigned long value, void *in), void *arg) { unsigned long value; int ret; while(len) { if(inform == MBSTRING_ASC) { value = *p++; len--; } else if(inform == MBSTRING_BMP) { value = *p++ << 8; value |= *p++; len -= 2; } else if(inform == MBSTRING_UNIV) { value = ((unsigned long)*p++) << 24; value |= ((unsigned long)*p++) << 16; value |= *p++ << 8; value |= *p++; len -= 4; } else { ret = UTF8_getc(p, len, &value); if(ret < 0) return -1; len -= ret; p += ret; } if(rfunc) { ret = rfunc(value, arg); if(ret <= 0) return ret; } } return 1; }
/* This function traverses a string and passes the value of each character * to an optional function along with a void * argument. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L250-L281
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
in_utf8
static int in_utf8(unsigned long value, void *arg) { int *nchar; nchar = arg; (*nchar)++; return 1; }
/* Various utility functions for traverse_string */ /* Just count number of characters */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L287-L293
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
out_utf8
static int out_utf8(unsigned long value, void *arg) { int *outlen; outlen = arg; *outlen += UTF8_putc(NULL, -1, value); return 1; }
/* Determine size of output as a UTF8 String */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L297-L303
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
type_str
static int type_str(unsigned long value, void *arg) { unsigned long types; types = *((unsigned long *)arg); if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value)) types &= ~B_ASN1_PRINTABLESTRING; if((types & B_ASN1_IA5STRING) && (value > 127)) types &= ~B_ASN1_IA5STRING; if((types & B_ASN1_T61STRING) && (value > 0xff)) types &= ~B_ASN1_T61STRING; if((types & B_ASN1_BMPSTRING) && (value > 0xffff)) types &= ~B_ASN1_BMPSTRING; if(!types) return -1; *((unsigned long *)arg) = types; return 1; }
/* Determine the "type" of a string: check each character against a * supplied "mask". */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L309-L324
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
cpy_asc
static int cpy_asc(unsigned long value, void *arg) { unsigned char **p, *q; p = arg; q = *p; *q = (unsigned char) value; (*p)++; return 1; }
/* Copy one byte per character ASCII like strings */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L328-L336
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
cpy_bmp
static int cpy_bmp(unsigned long value, void *arg) { unsigned char **p, *q; p = arg; q = *p; *q++ = (unsigned char) ((value >> 8) & 0xff); *q = (unsigned char) (value & 0xff); *p += 2; return 1; }
/* Copy two byte per character BMPStrings */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L340-L349
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
cpy_univ
static int cpy_univ(unsigned long value, void *arg) { unsigned char **p, *q; p = arg; q = *p; *q++ = (unsigned char) ((value >> 24) & 0xff); *q++ = (unsigned char) ((value >> 16) & 0xff); *q++ = (unsigned char) ((value >> 8) & 0xff); *q = (unsigned char) (value & 0xff); *p += 4; return 1; }
/* Copy four byte per character UniversalStrings */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L353-L364
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
cpy_utf8
static int cpy_utf8(unsigned long value, void *arg) { unsigned char **p; int ret; p = arg; /* We already know there is enough room so pass 0xff as the length */ ret = UTF8_putc(*p, 0xff, value); *p += ret; return 1; }
/* Copy to a UTF8String */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L368-L377
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
is_printable
static int is_printable(unsigned long value) { int ch; if(value > 0x7f) return 0; ch = (int) value; /* Note: we can't use 'isalnum' because certain accented * characters may count as alphanumeric in some environments. */ #ifndef CHARSET_EBCDIC if((ch >= 'a') && (ch <= 'z')) return 1; if((ch >= 'A') && (ch <= 'Z')) return 1; if((ch >= '0') && (ch <= '9')) return 1; if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1; #else /*CHARSET_EBCDIC*/ if((ch >= os_toascii['a']) && (ch <= os_toascii['z'])) return 1; if((ch >= os_toascii['A']) && (ch <= os_toascii['Z'])) return 1; if((ch >= os_toascii['0']) && (ch <= os_toascii['9'])) return 1; if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch])) return 1; #endif /*CHARSET_EBCDIC*/ return 0; }
/* Return 1 if the character is permitted in a PrintableString */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_mbstr.c#L380-L400
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
SetBlobCmp
static int SetBlobCmp(const void *elem1, const void *elem2 ) { const MYBLOB *b1 = (const MYBLOB *)elem1; const MYBLOB *b2 = (const MYBLOB *)elem2; int r; r = memcmp(b1->pbData, b2->pbData, b1->cbData < b2->cbData ? b1->cbData : b2->cbData); if(r != 0) return r; return b1->cbData-b2->cbData; }
/* SetBlobCmp * This function compares two elements of SET_OF block */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_set.c#L74-L85
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
i2d_ASN1_SET
int i2d_ASN1_SET(STACK_OF(OPENSSL_BLOCK) *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag, int ex_class, int is_set) { int ret=0,r; int i; unsigned char *p; unsigned char *pStart, *pTempMem; MYBLOB *rgSetBlob; int totSize; if (a == NULL) return(0); for (i=sk_OPENSSL_BLOCK_num(a)-1; i>=0; i--) ret+=i2d(sk_OPENSSL_BLOCK_value(a,i),NULL); r=ASN1_object_size(1,ret,ex_tag); if (pp == NULL) return(r); p= *pp; ASN1_put_object(&p,1,ret,ex_tag,ex_class); /* Modified by gp@nsj.co.jp */ /* And then again by Ben */ /* And again by Steve */ if(!is_set || (sk_OPENSSL_BLOCK_num(a) < 2)) { for (i=0; i<sk_OPENSSL_BLOCK_num(a); i++) i2d(sk_OPENSSL_BLOCK_value(a,i),&p); *pp=p; return(r); } pStart = p; /* Catch the beg of Setblobs*/ /* In this array we will store the SET blobs */ rgSetBlob = OPENSSL_malloc(sk_OPENSSL_BLOCK_num(a) * sizeof(MYBLOB)); if (rgSetBlob == NULL) { ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE); return(0); } for (i=0; i<sk_OPENSSL_BLOCK_num(a); i++) { rgSetBlob[i].pbData = p; /* catch each set encode blob */ i2d(sk_OPENSSL_BLOCK_value(a,i),&p); rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this SetBlob */ } *pp=p; totSize = p - pStart; /* This is the total size of all set blobs */ /* Now we have to sort the blobs. I am using a simple algo. *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/ qsort( rgSetBlob, sk_OPENSSL_BLOCK_num(a), sizeof(MYBLOB), SetBlobCmp); if (!(pTempMem = OPENSSL_malloc(totSize))) { ASN1err(ASN1_F_I2D_ASN1_SET,ERR_R_MALLOC_FAILURE); return(0); } /* Copy to temp mem */ p = pTempMem; for(i=0; i<sk_OPENSSL_BLOCK_num(a); ++i) { memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData); p += rgSetBlob[i].cbData; } /* Copy back to user mem*/ memcpy(pStart, pTempMem, totSize); OPENSSL_free(pTempMem); OPENSSL_free(rgSetBlob); return(r); }
/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_set.c#L88-L164
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
send_mem_chars
static int send_mem_chars(void *arg, const void *buf, int len) { unsigned char **out = arg; if(!out) return 1; memcpy(*out, buf, len); *out += len; return 1; }
/* never used */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strex.c#L87-L94
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
do_esc_char
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; }
/* This function handles display of * strings, one character at a time. * It is passed an unsigned long for each * character because it could come from 2 or even * 4 byte forms. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strex.c#L120-L165
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
do_buf
static int do_buf(unsigned char *buf, int buflen, int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg) { int i, outlen, len; unsigned char orflags, *p, *q; unsigned long c; p = buf; q = buf + buflen; outlen = 0; while(p != q) { if(p == buf && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_FIRST_ESC_2253; else orflags = 0; switch(type & BUF_TYPE_WIDTH_MASK) { case 4: c = ((unsigned long)*p++) << 24; c |= ((unsigned long)*p++) << 16; c |= ((unsigned long)*p++) << 8; c |= *p++; break; case 2: c = ((unsigned long)*p++) << 8; c |= *p++; break; case 1: c = *p++; break; case 0: i = UTF8_getc(p, buflen, &c); if(i < 0) return -1; /* Invalid UTF8String */ p += i; break; default: return -1; /* invalid width */ } if (p == q && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_LAST_ESC_2253; if(type & BUF_TYPE_CONVUTF8) { unsigned char utfbuf[6]; int utflen; utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); for(i = 0; i < utflen; i++) { /* We don't need to worry about setting orflags correctly * because if utflen==1 its value will be correct anyway * otherwise each character will be > 0x7f and so the * character will never be escaped on first and last. */ len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg); if(len < 0) return -1; outlen += len; } } else { len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg); if(len < 0) return -1; outlen += len; } } return outlen; }
/* This function sends each character in a buffer to * do_esc_char(). It interprets the content formats * and converts to or from UTF8 as appropriate. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strex.c#L175-L234
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
do_hex_dump
static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) { static const char hexdig[] = "0123456789ABCDEF"; unsigned char *p, *q; char hextmp[2]; if(arg) { p = buf; q = buf + buflen; while(p != q) { hextmp[0] = hexdig[*p >> 4]; hextmp[1] = hexdig[*p & 0xf]; if(!io_ch(arg, hextmp, 2)) return -1; p++; } } return buflen << 1; }
/* This function hex dumps a buffer of characters */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strex.c#L238-L254
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
do_dump
static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) { /* Placing the ASN1_STRING in a temp ASN1_TYPE allows * the DER encoding to readily obtained */ ASN1_TYPE t; unsigned char *der_buf, *p; int outlen, der_len; if(!io_ch(arg, "#", 1)) return -1; /* If we don't dump DER encoding just dump content octets */ if(!(lflags & ASN1_STRFLGS_DUMP_DER)) { outlen = do_hex_dump(io_ch, arg, str->data, str->length); if(outlen < 0) return -1; return outlen + 1; } t.type = str->type; t.value.ptr = (char *)str; der_len = i2d_ASN1_TYPE(&t, NULL); der_buf = OPENSSL_malloc(der_len); if(!der_buf) return -1; p = der_buf; i2d_ASN1_TYPE(&t, &p); outlen = do_hex_dump(io_ch, arg, der_buf, der_len); OPENSSL_free(der_buf); if(outlen < 0) return -1; return outlen + 1; }
/* "dump" a string. This is done when the type is unknown, * or the flags request it. We can either dump the content * octets or the entire DER encoding. This uses the RFC2253 * #01234 format. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strex.c#L262-L289
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
do_print_ex
static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str) { int outlen, len; int type; char quotes; unsigned char flags; quotes = 0; /* Keep a copy of escape flags */ flags = (unsigned char)(lflags & ESC_FLAGS); type = str->type; outlen = 0; if(lflags & ASN1_STRFLGS_SHOW_TYPE) { const char *tagname; tagname = ASN1_tag2str(type); outlen += strlen(tagname); if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1; outlen++; } /* Decide what to do with type, either dump content or display it */ /* Dump everything */ if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1; /* Ignore the string type */ else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1; else { /* Else determine width based on type */ if((type > 0) && (type < 31)) type = tag2nbyte[type]; else type = -1; if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1; } if(type == -1) { len = do_dump(lflags, io_ch, arg, str); if(len < 0) return -1; outlen += len; return outlen; } if(lflags & ASN1_STRFLGS_UTF8_CONVERT) { /* Note: if string is UTF8 and we want * to convert to UTF8 then we just interpret * it as 1 byte per character to avoid converting * twice. */ if(!type) type = 1; else type |= BUF_TYPE_CONVUTF8; } len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL); if(len < 0) return -1; outlen += len; if(quotes) outlen += 2; if(!arg) return outlen; if(quotes && !io_ch(arg, "\"", 1)) return -1; if(do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) return -1; if(quotes && !io_ch(arg, "\"", 1)) return -1; return outlen; }
/* This is the main function, print out an * ASN1_STRING taking note of various escape * and display options. Returns number of * characters written or -1 if an error * occurred. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strex.c#L314-L377
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
do_indent
static int do_indent(char_io *io_ch, void *arg, int indent) { int i; for(i = 0; i < indent; i++) if(!io_ch(arg, " ", 1)) return 0; return 1; }
/* Used for line indenting: print 'indent' spaces */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strex.c#L381-L387
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
X509_NAME_print_ex
int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) { if(flags == XN_FLAG_COMPAT) return X509_NAME_print(out, nm, indent); return do_name_ex(send_bio_chars, out, nm, indent, flags); }
/* Wrappers round the main functions */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strex.c#L519-L524
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_STRING_to_UTF8
int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) { ASN1_STRING stmp, *str = &stmp; int mbflag, type, ret; if(!in) return -1; type = in->type; if((type < 0) || (type > 30)) return -1; mbflag = tag2nbyte[type]; if(mbflag == -1) return -1; mbflag |= MBSTRING_FLAG; stmp.data = NULL; ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); if(ret < 0) return ret; *out = stmp.data; return stmp.length; }
/* Utility function: convert any string type to UTF8, returns number of bytes * in output string or a negative error code */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strex.c#L559-L574
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_STRING_set_default_mask_asc
int ASN1_STRING_set_default_mask_asc(const char *p) { unsigned long mask; char *end; if(!strncmp(p, "MASK:", 5)) { if(!p[5]) return 0; mask = strtoul(p + 5, &end, 0); if(*end) return 0; } else if(!strcmp(p, "nombstr")) mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)); else if(!strcmp(p, "pkix")) mask = ~((unsigned long)B_ASN1_T61STRING); else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING; else if(!strcmp(p, "default")) mask = 0xFFFFFFFFL; else return 0; ASN1_STRING_set_default_mask(mask); return 1; }
/* This function sets the default to various "flavours" of configuration. * based on an ASCII string. Currently this is: * MASK:XXXX : a numerical mask value. * nobmp : Don't use BMPStrings (just Printable, T61). * pkix : PKIX recommendation in RFC2459. * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004). * default: the default value, Printable, T61, BMP. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_strnid.c#L98-L116
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
UTF8_getc
int UTF8_getc(const unsigned char *str, int len, unsigned long *val) { const unsigned char *p; unsigned long value; int ret; if(len <= 0) return 0; p = str; /* Check syntax and work out the encoded value (if correct) */ if((*p & 0x80) == 0) { value = *p++ & 0x7f; ret = 1; } else if((*p & 0xe0) == 0xc0) { if(len < 2) return -1; if((p[1] & 0xc0) != 0x80) return -3; value = (*p++ & 0x1f) << 6; value |= *p++ & 0x3f; if(value < 0x80) return -4; ret = 2; } else if((*p & 0xf0) == 0xe0) { if(len < 3) return -1; if( ((p[1] & 0xc0) != 0x80) || ((p[2] & 0xc0) != 0x80) ) return -3; value = (*p++ & 0xf) << 12; value |= (*p++ & 0x3f) << 6; value |= *p++ & 0x3f; if(value < 0x800) return -4; ret = 3; } else if((*p & 0xf8) == 0xf0) { if(len < 4) return -1; if( ((p[1] & 0xc0) != 0x80) || ((p[2] & 0xc0) != 0x80) || ((p[3] & 0xc0) != 0x80) ) return -3; value = ((unsigned long)(*p++ & 0x7)) << 18; value |= (*p++ & 0x3f) << 12; value |= (*p++ & 0x3f) << 6; value |= *p++ & 0x3f; if(value < 0x10000) return -4; ret = 4; } else if((*p & 0xfc) == 0xf8) { if(len < 5) return -1; if( ((p[1] & 0xc0) != 0x80) || ((p[2] & 0xc0) != 0x80) || ((p[3] & 0xc0) != 0x80) || ((p[4] & 0xc0) != 0x80) ) return -3; value = ((unsigned long)(*p++ & 0x3)) << 24; value |= ((unsigned long)(*p++ & 0x3f)) << 18; value |= ((unsigned long)(*p++ & 0x3f)) << 12; value |= (*p++ & 0x3f) << 6; value |= *p++ & 0x3f; if(value < 0x200000) return -4; ret = 5; } else if((*p & 0xfe) == 0xfc) { if(len < 6) return -1; if( ((p[1] & 0xc0) != 0x80) || ((p[2] & 0xc0) != 0x80) || ((p[3] & 0xc0) != 0x80) || ((p[4] & 0xc0) != 0x80) || ((p[5] & 0xc0) != 0x80) ) return -3; value = ((unsigned long)(*p++ & 0x1)) << 30; value |= ((unsigned long)(*p++ & 0x3f)) << 24; value |= ((unsigned long)(*p++ & 0x3f)) << 18; value |= ((unsigned long)(*p++ & 0x3f)) << 12; value |= (*p++ & 0x3f) << 6; value |= *p++ & 0x3f; if(value < 0x4000000) return -4; ret = 6; } else return -2; *val = value; return ret; }
/* UTF8 utilities */ /* This parses a UTF8 string one character at a time. It is passed a pointer * to the string and the length of the string. It sets 'value' to the value of * the current character. It returns the number of characters read or a * negative error code: * -1 = string too short * -2 = illegal character * -3 = subsequent characters not of the form 10xxxxxx * -4 = character encoded incorrectly (not minimal length). */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_utf8.c#L76-L146
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
UTF8_putc
int UTF8_putc(unsigned char *str, int len, unsigned long value) { if(!str) len = 6; /* Maximum we will need */ else if(len <= 0) return -1; if(value < 0x80) { if(str) *str = (unsigned char)value; return 1; } if(value < 0x800) { if(len < 2) return -1; if(str) { *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0); *str = (unsigned char)((value & 0x3f) | 0x80); } return 2; } if(value < 0x10000) { if(len < 3) return -1; if(str) { *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0); *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); *str = (unsigned char)((value & 0x3f) | 0x80); } return 3; } if(value < 0x200000) { if(len < 4) return -1; if(str) { *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0); *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80); *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); *str = (unsigned char)((value & 0x3f) | 0x80); } return 4; } if(value < 0x4000000) { if(len < 5) return -1; if(str) { *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8); *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80); *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80); *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); *str = (unsigned char)((value & 0x3f) | 0x80); } return 5; } if(len < 6) return -1; if(str) { *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc); *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80); *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80); *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80); *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); *str = (unsigned char)((value & 0x3f) | 0x80); } return 6; }
/* This takes a character 'value' and writes the UTF8 encoded value in * 'str' where 'str' is a buffer containing 'len' characters. Returns * the number of characters written or -1 if 'len' is too small. 'str' can * be set to NULL in which case it just returns the number of characters. * It will need at most 6 characters. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/a_utf8.c#L155-L211
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_put_object
void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, int xclass) { unsigned char *p= *pp; int i, ttag; i=(constructed)?V_ASN1_CONSTRUCTED:0; i|=(xclass&V_ASN1_PRIVATE); if (tag < 31) *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); else { *(p++)=i|V_ASN1_PRIMITIVE_TAG; for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7; ttag = i; while(i-- > 0) { p[i] = tag & 0x7f; if(i != (ttag - 1)) p[i] |= 0x80; tag >>= 7; } p += ttag; } if (constructed == 2) *(p++)=0x80; else asn1_put_length(&p,length); *pp=p; }
/* class 0 is constructed * constructed == 2 for indefinite length constructed */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn1_lib.c#L195-L223
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
B64_write_ASN1
static int B64_write_ASN1(BIO *out, ASN1_VALUE *val, BIO *in, int flags, const ASN1_ITEM *it) { BIO *b64; int r; b64 = BIO_new(BIO_f_base64()); if(!b64) { ASN1err(ASN1_F_B64_WRITE_ASN1,ERR_R_MALLOC_FAILURE); return 0; } /* prepend the b64 BIO so all data is base64 encoded. */ out = BIO_push(b64, out); r = i2d_ASN1_bio_stream(out, val, in, flags, it); (void)BIO_flush(out); BIO_pop(out); BIO_free(b64); return r; }
/* Base 64 read and write of ASN1 structure */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_mime.c#L148-L167
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
PEM_write_bio_ASN1_stream
int PEM_write_bio_ASN1_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags, const char *hdr, const ASN1_ITEM *it) { int r; BIO_printf(out, "-----BEGIN %s-----\n", hdr); r = B64_write_ASN1(out, val, in, flags, it); BIO_printf(out, "-----END %s-----\n", hdr); return r; }
/* Streaming ASN1 PEM write */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_mime.c#L171-L180
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
asn1_write_micalg
static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs) { const EVP_MD *md; int i, have_unknown = 0, write_comma, ret = 0, md_nid; have_unknown = 0; write_comma = 0; for (i = 0; i < sk_X509_ALGOR_num(mdalgs); i++) { if (write_comma) BIO_write(out, ",", 1); write_comma = 1; md_nid = OBJ_obj2nid(sk_X509_ALGOR_value(mdalgs, i)->algorithm); md = EVP_get_digestbynid(md_nid); if (md && md->md_ctrl) { int rv; char *micstr; rv = md->md_ctrl(NULL, EVP_MD_CTRL_MICALG, 0, &micstr); if (rv > 0) { BIO_puts(out, micstr); OPENSSL_free(micstr); continue; } if (rv != -2) goto err; } switch(md_nid) { case NID_sha1: BIO_puts(out, "sha1"); break; case NID_md5: BIO_puts(out, "md5"); break; case NID_sha256: BIO_puts(out, "sha-256"); break; case NID_sha384: BIO_puts(out, "sha-384"); break; case NID_sha512: BIO_puts(out, "sha-512"); break; case NID_id_GostR3411_94: BIO_puts(out, "gostr3411-94"); goto err; break; default: if (have_unknown) write_comma = 0; else { BIO_puts(out, "unknown"); have_unknown = 1; } break; } } ret = 1; err: return ret; }
/* Generate the MIME "micalg" parameter from RFC3851, RFC4490 */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_mime.c#L202-L274
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
SMIME_write_ASN1
int SMIME_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags, int ctype_nid, int econt_nid, STACK_OF(X509_ALGOR) *mdalgs, const ASN1_ITEM *it) { char bound[33], c; int i; const char *mime_prefix, *mime_eol, *cname = "smime.p7m"; const char *msg_type=NULL; if (flags & SMIME_OLDMIME) mime_prefix = "application/x-pkcs7-"; else mime_prefix = "application/pkcs7-"; if (flags & SMIME_CRLFEOL) mime_eol = "\r\n"; else mime_eol = "\n"; if((flags & SMIME_DETACHED) && data) { /* We want multipart/signed */ /* Generate a random boundary */ RAND_pseudo_bytes((unsigned char *)bound, 32); for(i = 0; i < 32; i++) { c = bound[i] & 0xf; if(c < 10) c += '0'; else c += 'A' - 10; bound[i] = c; } bound[32] = 0; BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); BIO_printf(bio, "Content-Type: multipart/signed;"); BIO_printf(bio, " protocol=\"%ssignature\";", mime_prefix); BIO_puts(bio, " micalg=\""); asn1_write_micalg(bio, mdalgs); BIO_printf(bio, "\"; boundary=\"----%s\"%s%s", bound, mime_eol, mime_eol); BIO_printf(bio, "This is an S/MIME signed message%s%s", mime_eol, mime_eol); /* Now write out the first part */ BIO_printf(bio, "------%s%s", bound, mime_eol); if (!asn1_output_data(bio, data, val, flags, it)) return 0; BIO_printf(bio, "%s------%s%s", mime_eol, bound, mime_eol); /* Headers for signature */ BIO_printf(bio, "Content-Type: %ssignature;", mime_prefix); BIO_printf(bio, " name=\"smime.p7s\"%s", mime_eol); BIO_printf(bio, "Content-Transfer-Encoding: base64%s", mime_eol); BIO_printf(bio, "Content-Disposition: attachment;"); BIO_printf(bio, " filename=\"smime.p7s\"%s%s", mime_eol, mime_eol); B64_write_ASN1(bio, val, NULL, 0, it); BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound, mime_eol, mime_eol); return 1; } /* Determine smime-type header */ if (ctype_nid == NID_pkcs7_enveloped) msg_type = "enveloped-data"; else if (ctype_nid == NID_pkcs7_signed) { if (econt_nid == NID_id_smime_ct_receipt) msg_type = "signed-receipt"; else if (sk_X509_ALGOR_num(mdalgs) >= 0) msg_type = "signed-data"; else msg_type = "certs-only"; } else if (ctype_nid == NID_id_smime_ct_compressedData) { msg_type = "compressed-data"; cname = "smime.p7z"; } /* MIME headers */ BIO_printf(bio, "MIME-Version: 1.0%s", mime_eol); BIO_printf(bio, "Content-Disposition: attachment;"); BIO_printf(bio, " filename=\"%s\"%s", cname, mime_eol); BIO_printf(bio, "Content-Type: %smime;", mime_prefix); if (msg_type) BIO_printf(bio, " smime-type=%s;", msg_type); BIO_printf(bio, " name=\"%s\"%s", cname, mime_eol); BIO_printf(bio, "Content-Transfer-Encoding: base64%s%s", mime_eol, mime_eol); if (!B64_write_ASN1(bio, val, data, flags, it)) return 0; BIO_printf(bio, "%s", mime_eol); return 1; }
/* SMIME sender */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_mime.c#L278-L369
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
asn1_output_data
static int asn1_output_data(BIO *out, BIO *data, ASN1_VALUE *val, int flags, const ASN1_ITEM *it) { BIO *tmpbio; const ASN1_AUX *aux = it->funcs; ASN1_STREAM_ARG sarg; if (!(flags & SMIME_DETACHED)) { SMIME_crlf_copy(data, out, flags); return 1; } if (!aux || !aux->asn1_cb) { ASN1err(ASN1_F_ASN1_OUTPUT_DATA, ASN1_R_STREAMING_NOT_SUPPORTED); return 0; } sarg.out = out; sarg.ndef_bio = NULL; sarg.boundary = NULL; /* Let ASN1 code prepend any needed BIOs */ if (aux->asn1_cb(ASN1_OP_DETACHED_PRE, &val, it, &sarg) <= 0) return 0; /* Copy data across, passing through filter BIOs for processing */ SMIME_crlf_copy(data, sarg.ndef_bio, flags); /* Finalize structure */ if (aux->asn1_cb(ASN1_OP_DETACHED_POST, &val, it, &sarg) <= 0) return 0; /* Now remove any digests prepended to the BIO */ while (sarg.ndef_bio != out) { tmpbio = BIO_pop(sarg.ndef_bio); BIO_free(sarg.ndef_bio); sarg.ndef_bio = tmpbio; } return 1; }
/* Handle output of ASN1 data */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_mime.c#L374-L421
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
SMIME_crlf_copy
int SMIME_crlf_copy(BIO *in, BIO *out, int flags) { BIO *bf; char eol; int len; char linebuf[MAX_SMLEN]; /* Buffer output so we don't write one line at a time. This is * useful when streaming as we don't end up with one OCTET STRING * per line. */ bf = BIO_new(BIO_f_buffer()); if (!bf) return 0; out = BIO_push(bf, out); if(flags & SMIME_BINARY) { while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) BIO_write(out, linebuf, len); } else { if(flags & SMIME_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) { eol = strip_eol(linebuf, &len); if (len) BIO_write(out, linebuf, len); if(eol) BIO_write(out, "\r\n", 2); } } (void)BIO_flush(out); BIO_pop(out); BIO_free(bf); return 1; }
/* Copy text from one BIO to another making the output CRLF at EOL */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_mime.c#L532-L567
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
SMIME_text
int SMIME_text(BIO *in, BIO *out) { char iobuf[4096]; int len; STACK_OF(MIME_HEADER) *headers; MIME_HEADER *hdr; if (!(headers = mime_parse_hdr(in))) { ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_PARSE_ERROR); return 0; } if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_MIME_NO_CONTENT_TYPE); sk_MIME_HEADER_pop_free(headers, mime_hdr_free); return 0; } if (strcmp (hdr->value, "text/plain")) { ASN1err(ASN1_F_SMIME_TEXT,ASN1_R_INVALID_MIME_TYPE); ERR_add_error_data(2, "type: ", hdr->value); sk_MIME_HEADER_pop_free(headers, mime_hdr_free); return 0; } sk_MIME_HEADER_pop_free(headers, mime_hdr_free); while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0) BIO_write(out, iobuf, len); if (len < 0) return 0; return 1; }
/* Strip off headers if they are text/plain */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_mime.c#L570-L598
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
multi_split
static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) { char linebuf[MAX_SMLEN]; int len, blen; int eol = 0, next_eol = 0; BIO *bpart = NULL; STACK_OF(BIO) *parts; char state, part, first; blen = strlen(bound); part = 0; state = 0; first = 1; parts = sk_BIO_new_null(); *ret = parts; while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { state = mime_bound_check(linebuf, len, bound, blen); if(state == 1) { first = 1; part++; } else if(state == 2) { sk_BIO_push(parts, bpart); return 1; } else if(part) { /* Strip CR+LF from linebuf */ next_eol = strip_eol(linebuf, &len); if(first) { first = 0; if(bpart) sk_BIO_push(parts, bpart); bpart = BIO_new(BIO_s_mem()); BIO_set_mem_eof_return(bpart, 0); } else if (eol) BIO_write(bpart, "\r\n", 2); eol = next_eol; if (len) BIO_write(bpart, linebuf, len); } } return 0; }
/* Split a multipart/XXX message body into component parts: result is * canonical parts in a STACK of bios */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_mime.c#L604-L643
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
mime_bound_check
static int mime_bound_check(char *line, int linelen, char *bound, int blen) { if(linelen == -1) linelen = strlen(line); if(blen == -1) blen = strlen(bound); /* Quickly eliminate if line length too short */ if(blen + 2 > linelen) return 0; /* Check for part boundary */ if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) { if(!strncmp(line + blen + 2, "--", 2)) return 2; else return 1; } return 0; }
/* Check for a multipart boundary. Returns: * 0 : no boundary * 1 : part boundary * 2 : final boundary */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_mime.c#L912-L924
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
do_create
static int do_create(char *value, char *name) { int nid; ASN1_OBJECT *oid; char *ln, *ostr, *p, *lntmp; p = strrchr(value, ','); if (!p) { ln = name; ostr = value; } else { ln = NULL; ostr = p + 1; if (!*ostr) return 0; while(isspace((unsigned char)*ostr)) ostr++; } nid = OBJ_create(ostr, name, ln); if (nid == NID_undef) return 0; if (p) { ln = value; while(isspace((unsigned char)*ln)) ln++; p--; while(isspace((unsigned char)*p)) { if (p == ln) return 0; p--; } p++; lntmp = OPENSSL_malloc((p - ln) + 1); if (lntmp == NULL) return 0; memcpy(lntmp, ln, p - ln); lntmp[p - ln] = 0; oid = OBJ_nid2obj(nid); oid->ln = lntmp; } return 1; }
/* Create an OID based on a name value pair. Accept two formats. * shortname = 1.2.3.4 * shortname = some long name, 1.2.3.4 */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/asn_moid.c#L111-L158
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_TYPE_get_octetstring
int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, int max_len) { int ret,num; unsigned char *p; if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) { ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); return(-1); } p=M_ASN1_STRING_data(a->value.octet_string); ret=M_ASN1_STRING_length(a->value.octet_string); if (ret < max_len) num=ret; else num=max_len; memcpy(data,p,num); return(ret); }
/* int max_len: for returned value */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/evp_asn1.c#L75-L94
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_TYPE_get_int_octetstring
int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, int max_len) { int ret= -1,n; ASN1_INTEGER *ai=NULL; ASN1_OCTET_STRING *os=NULL; const unsigned char *p; long length; ASN1_const_CTX c; if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) { goto err; } p=M_ASN1_STRING_data(a->value.sequence); length=M_ASN1_STRING_length(a->value.sequence); c.pp= &p; c.p=p; c.max=p+length; c.error=ASN1_R_DATA_IS_WRONG; M_ASN1_D2I_start_sequence(); c.q=c.p; if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err; c.slen-=(c.p-c.q); c.q=c.p; if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err; c.slen-=(c.p-c.q); if (!M_ASN1_D2I_end_sequence()) goto err; if (num != NULL) *num=ASN1_INTEGER_get(ai); ret=M_ASN1_STRING_length(os); if (max_len > ret) n=ret; else n=max_len; if (data != NULL) memcpy(data,M_ASN1_STRING_data(os),n); if (0) { err: ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); } if (os != NULL) M_ASN1_OCTET_STRING_free(os); if (ai != NULL) M_ASN1_INTEGER_free(ai); return(ret); }
/* we return the actual length..., num may be missing, in which * case, set it to zero */ /* int max_len: for returned value */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/evp_asn1.c#L138-L188
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
i2a_ASN1_ENUMERATED
int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) { int i,n=0; static const char *h="0123456789ABCDEF"; char buf[2]; if (a == NULL) return(0); if (a->length == 0) { if (BIO_write(bp,"00",2) != 2) goto err; n=2; } else { for (i=0; i<a->length; i++) { if ((i != 0) && (i%35 == 0)) { if (BIO_write(bp,"\\\n",2) != 2) goto err; n+=2; } buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; buf[1]=h[((unsigned char)a->data[i] )&0x0f]; if (BIO_write(bp,buf,2) != 2) goto err; n+=2; } } return(n); err: return(-1); }
/* Based on a_int.c: equivalent ENUMERATED functions */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/f_enum.c#L66-L97
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
pkey_cb
static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) { /* Since the structure must still be valid use ASN1_OP_FREE_PRE */ if(operation == ASN1_OP_FREE_PRE) { PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval; if (key->pkey->value.octet_string) OPENSSL_cleanse(key->pkey->value.octet_string->data, key->pkey->value.octet_string->length); } return 1; }
/* Minor tweak to operation: zero private key data */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/p8_pkey.c#L65-L76
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
NETSCAPE_SPKI_print
int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) { EVP_PKEY *pkey; ASN1_IA5STRING *chal; int i, n; char *s; BIO_printf(out, "Netscape SPKI:\n"); i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm); BIO_printf(out," Public Key Algorithm: %s\n", (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); pkey = X509_PUBKEY_get(spki->spkac->pubkey); if(!pkey) BIO_printf(out, " Unable to load public key\n"); else { EVP_PKEY_print_public(out, pkey, 4, NULL); EVP_PKEY_free(pkey); } chal = spki->spkac->challenge; if(chal->length) BIO_printf(out, " Challenge String: %s\n", chal->data); i=OBJ_obj2nid(spki->sig_algor->algorithm); BIO_printf(out," Signature Algorithm: %s", (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); n=spki->signature->length; s=(char *)spki->signature->data; for (i=0; i<n; i++) { if ((i%18) == 0) BIO_write(out,"\n ",7); BIO_printf(out,"%02x%s",(unsigned char)s[i], ((i+1) == n)?"":":"); } BIO_write(out,"\n",1); return 1; }
/* Print out an SPKI */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/t_spki.c#L73-L107
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
X509_CERT_AUX_print
int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent) { char oidstr[80], first; int i; if(!aux) return 1; if(aux->trust) { first = 1; BIO_printf(out, "%*sTrusted Uses:\n%*s", indent, "", indent + 2, ""); for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) { if(!first) BIO_puts(out, ", "); else first = 0; OBJ_obj2txt(oidstr, sizeof oidstr, sk_ASN1_OBJECT_value(aux->trust, i), 0); BIO_puts(out, oidstr); } BIO_puts(out, "\n"); } else BIO_printf(out, "%*sNo Trusted Uses.\n", indent, ""); if(aux->reject) { first = 1; BIO_printf(out, "%*sRejected Uses:\n%*s", indent, "", indent + 2, ""); for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) { if(!first) BIO_puts(out, ", "); else first = 0; OBJ_obj2txt(oidstr, sizeof oidstr, sk_ASN1_OBJECT_value(aux->reject, i), 0); BIO_puts(out, oidstr); } BIO_puts(out, "\n"); } else BIO_printf(out, "%*sNo Rejected Uses.\n", indent, ""); if(aux->alias) BIO_printf(out, "%*sAlias: %s\n", indent, "", aux->alias->data); if(aux->keyid) { BIO_printf(out, "%*sKey Id: ", indent, ""); for(i = 0; i < aux->keyid->length; i++) BIO_printf(out, "%s%02X", i ? ":" : "", aux->keyid->data[i]); BIO_write(out,"\n",1); } return 1; }
/* X509_CERT_AUX and string set routines */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/t_x509a.c#L68-L110
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_item_ex_d2i
int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx) { const ASN1_TEMPLATE *tt, *errtt = NULL; const ASN1_COMPAT_FUNCS *cf; const ASN1_EXTERN_FUNCS *ef; const ASN1_AUX *aux = it->funcs; ASN1_aux_cb *asn1_cb; const unsigned char *p = NULL, *q; unsigned char *wp=NULL; /* BIG FAT WARNING! BREAKS CONST WHERE USED */ unsigned char imphack = 0, oclass; char seq_eoc, seq_nolen, cst, isopt; long tmplen; int i; int otag; int ret = 0; ASN1_VALUE **pchptr, *ptmpval; if (!pval) return 0; if (aux && aux->asn1_cb) asn1_cb = aux->asn1_cb; else asn1_cb = 0; switch(it->itype) { case ASN1_ITYPE_PRIMITIVE: if (it->templates) { /* tagging or OPTIONAL is currently illegal on an item * template because the flags can't get passed down. * In practice this isn't a problem: we include the * relevant flags from the item template in the * template itself. */ if ((tag != -1) || opt) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); goto err; } return asn1_template_ex_d2i(pval, in, len, it->templates, opt, ctx); } return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt, ctx); break; case ASN1_ITYPE_MSTRING: p = *in; /* Just read in tag and class */ ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx); if (!ret) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } /* Must be UNIVERSAL class */ if (oclass != V_ASN1_UNIVERSAL) { /* If OPTIONAL, assume this is OK */ if (opt) return -1; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL); goto err; } /* Check tag matches bit map */ if (!(ASN1_tag2bit(otag) & it->utype)) { /* If OPTIONAL, assume this is OK */ if (opt) return -1; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_WRONG_TAG); goto err; } return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx); case ASN1_ITYPE_EXTERN: /* Use new style d2i */ ef = it->funcs; return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx); case ASN1_ITYPE_COMPAT: /* we must resort to old style evil hackery */ cf = it->funcs; /* If OPTIONAL see if it is there */ if (opt) { int exptag; p = *in; if (tag == -1) exptag = it->utype; else exptag = tag; /* Don't care about anything other than presence * of expected tag */ ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx); if (!ret) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } if (ret == -1) return -1; } /* This is the old style evil hack IMPLICIT handling: * since the underlying code is expecting a tag and * class other than the one present we change the * buffer temporarily then change it back afterwards. * This doesn't and never did work for tags > 30. * * Yes this is *horrible* but it is only needed for * old style d2i which will hopefully not be around * for much longer. * FIXME: should copy the buffer then modify it so * the input buffer can be const: we should *always* * copy because the old style d2i might modify the * buffer. */ if (tag != -1) { wp = *(unsigned char **)in; imphack = *wp; if (p == NULL) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | it->utype); } ptmpval = cf->asn1_d2i(pval, in, len); if (tag != -1) *wp = imphack; if (ptmpval) return 1; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; case ASN1_ITYPE_CHOICE: if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) goto auxerr; /* Allocate structure */ if (!*pval && !ASN1_item_ex_new(pval, it)) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } /* CHOICE type, try each possibility in turn */ p = *in; for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) { pchptr = asn1_get_field_ptr(pval, tt); /* We mark field as OPTIONAL so its absence * can be recognised. */ ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx); /* If field not present, try the next one */ if (ret == -1) continue; /* If positive return, read OK, break loop */ if (ret > 0) break; /* Otherwise must be an ASN1 parsing error */ errtt = tt; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } /* Did we fall off the end without reading anything? */ if (i == it->tcount) { /* If OPTIONAL, this is OK */ if (opt) { /* Free and zero it */ ASN1_item_ex_free(pval, it); return -1; } ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE); goto err; } asn1_set_choice_selector(pval, i, it); *in = p; if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) goto auxerr; return 1; case ASN1_ITYPE_NDEF_SEQUENCE: case ASN1_ITYPE_SEQUENCE: p = *in; tmplen = len; /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ if (tag == -1) { tag = V_ASN1_SEQUENCE; aclass = V_ASN1_UNIVERSAL; } /* Get SEQUENCE length and update len, p */ ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx); if (!ret) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } else if (ret == -1) return -1; if (aux && (aux->flags & ASN1_AFLG_BROKEN)) { len = tmplen - (p - *in); seq_nolen = 1; } /* If indefinite we don't do a length check */ else seq_nolen = seq_eoc; if (!cst) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED); goto err; } if (!*pval && !ASN1_item_ex_new(pval, it)) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); goto err; } if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) goto auxerr; /* Get each field entry */ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) { const ASN1_TEMPLATE *seqtt; ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 1); if (!seqtt) goto err; pseqval = asn1_get_field_ptr(pval, seqtt); /* Have we ran out of data? */ if (!len) break; q = p; if (asn1_check_eoc(&p, len)) { if (!seq_eoc) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC); goto err; } len -= p - q; seq_eoc = 0; q = p; break; } /* This determines the OPTIONAL flag value. The field * cannot be omitted if it is the last of a SEQUENCE * and there is still data to be read. This isn't * strictly necessary but it increases efficiency in * some cases. */ if (i == (it->tcount - 1)) isopt = 0; else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL); /* attempt to read in field, allowing each to be * OPTIONAL */ ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx); if (!ret) { errtt = seqtt; goto err; } else if (ret == -1) { /* OPTIONAL component absent. * Free and zero the field. */ ASN1_template_free(pseqval, seqtt); continue; } /* Update length */ len -= p - q; } /* Check for EOC if expecting one */ if (seq_eoc && !asn1_check_eoc(&p, len)) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); goto err; } /* Check all data read */ if (!seq_nolen && len) { ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH); goto err; } /* If we get here we've got no more data in the SEQUENCE, * however we may not have read all fields so check all * remaining are OPTIONAL and clear any that are. */ for (; i < it->tcount; tt++, i++) { const ASN1_TEMPLATE *seqtt; seqtt = asn1_do_adb(pval, tt, 1); if (!seqtt) goto err; if (seqtt->flags & ASN1_TFLG_OPTIONAL) { ASN1_VALUE **pseqval; pseqval = asn1_get_field_ptr(pval, seqtt); ASN1_template_free(pseqval, seqtt); } else { errtt = seqtt; ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING); goto err; } } /* Save encoding */ if (!asn1_enc_save(pval, *in, p - *in, it)) goto auxerr; *in = p; if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) goto auxerr; return 1; default: return 0; } auxerr: ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); err: ASN1_item_ex_free(pval, it); if (errtt) ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname); else ERR_add_error_data(2, "Type=", it->sname); return 0; }
/* Decode an item, taking care of IMPLICIT tagging, if any. * If 'opt' set and tag mismatch return -1 to handle OPTIONAL */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/tasn_dec.c#L154-L526
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
asn1_template_ex_d2i
static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long inlen, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx) { int flags, aclass; int ret; long len; const unsigned char *p, *q; char exp_eoc; if (!val) return 0; flags = tt->flags; aclass = flags & ASN1_TFLG_TAG_CLASS; p = *in; /* Check if EXPLICIT tag expected */ if (flags & ASN1_TFLG_EXPTAG) { char cst; /* Need to work out amount of data available to the inner * content and where it starts: so read in EXPLICIT header to * get the info. */ ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, &p, inlen, tt->tag, aclass, opt, ctx); q = p; if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; } else if (ret == -1) return -1; if (!cst) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); return 0; } /* We've found the field so it can't be OPTIONAL now */ ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); if (!ret) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); return 0; } /* We read the field in OK so update length */ len -= p - q; if (exp_eoc) { /* If NDEF we must have an EOC here */ if (!asn1_check_eoc(&p, len)) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_MISSING_EOC); goto err; } } else { /* Otherwise we must hit the EXPLICIT tag end or its * an error */ if (len) { ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH); goto err; } } } else return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx); *in = p; return 1; err: ASN1_template_free(val, tt); return 0; }
/* Templates are handled with two separate functions. * One handles any EXPLICIT tag and the other handles the rest. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/tasn_dec.c#L532-L616
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
asn1_ex_c2i
int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it) { ASN1_VALUE **opval = NULL; ASN1_STRING *stmp; ASN1_TYPE *typ = NULL; int ret = 0; const ASN1_PRIMITIVE_FUNCS *pf; ASN1_INTEGER **tint; pf = it->funcs; if (pf && pf->prim_c2i) return pf->prim_c2i(pval, cont, len, utype, free_cont, it); /* If ANY type clear type and set pointer to internal value */ if (it->utype == V_ASN1_ANY) { if (!*pval) { typ = ASN1_TYPE_new(); if (typ == NULL) goto err; *pval = (ASN1_VALUE *)typ; } else typ = (ASN1_TYPE *)*pval; if (utype != typ->type) ASN1_TYPE_set(typ, utype, NULL); opval = pval; pval = &typ->value.asn1_value; } switch(utype) { case V_ASN1_OBJECT: if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err; break; case V_ASN1_NULL: if (len) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_NULL_IS_WRONG_LENGTH); goto err; } *pval = (ASN1_VALUE *)1; break; case V_ASN1_BOOLEAN: if (len != 1) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BOOLEAN_IS_WRONG_LENGTH); goto err; } else { ASN1_BOOLEAN *tbool; tbool = (ASN1_BOOLEAN *)pval; *tbool = *cont; } break; case V_ASN1_BIT_STRING: if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) goto err; break; case V_ASN1_INTEGER: case V_ASN1_NEG_INTEGER: case V_ASN1_ENUMERATED: case V_ASN1_NEG_ENUMERATED: tint = (ASN1_INTEGER **)pval; if (!c2i_ASN1_INTEGER(tint, &cont, len)) goto err; /* Fixup type to match the expected form */ (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG); break; case V_ASN1_OCTET_STRING: case V_ASN1_NUMERICSTRING: case V_ASN1_PRINTABLESTRING: case V_ASN1_T61STRING: case V_ASN1_VIDEOTEXSTRING: case V_ASN1_IA5STRING: case V_ASN1_UTCTIME: case V_ASN1_GENERALIZEDTIME: case V_ASN1_GRAPHICSTRING: case V_ASN1_VISIBLESTRING: case V_ASN1_GENERALSTRING: case V_ASN1_UNIVERSALSTRING: case V_ASN1_BMPSTRING: case V_ASN1_UTF8STRING: case V_ASN1_OTHER: case V_ASN1_SET: case V_ASN1_SEQUENCE: default: if (utype == V_ASN1_BMPSTRING && (len & 1)) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BMPSTRING_IS_WRONG_LENGTH); goto err; } if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) { ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH); goto err; } /* All based on ASN1_STRING and handled the same */ if (!*pval) { stmp = ASN1_STRING_type_new(utype); if (!stmp) { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); goto err; } *pval = (ASN1_VALUE *)stmp; } else { stmp = (ASN1_STRING *)*pval; stmp->type = utype; } /* If we've already allocated a buffer use it */ if (*free_cont) { if (stmp->data) OPENSSL_free(stmp->data); stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ stmp->length = len; *free_cont = 0; } else { if (!ASN1_STRING_set(stmp, cont, len)) { ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE); ASN1_STRING_free(stmp); *pval = NULL; goto err; } } break; } /* If ASN1_ANY and NULL type fix up value */ if (typ && (utype == V_ASN1_NULL)) typ->value.ptr = NULL; ret = 1; err: if (!ret) { ASN1_TYPE_free(typ); if (opval) *opval = NULL; } return ret; }
/* Translate ASN1 content octets into a structure */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/tasn_dec.c#L919-L1080
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
asn1_find_end
static int asn1_find_end(const unsigned char **in, long len, char inf) { int expected_eoc; long plen; const unsigned char *p = *in, *q; /* If not indefinite length constructed just add length */ if (inf == 0) { *in += len; return 1; } expected_eoc = 1; /* Indefinite length constructed form. Find the end when enough EOCs * are found. If more indefinite length constructed headers * are encountered increment the expected eoc count otherwise just * skip to the end of the data. */ while (len > 0) { if(asn1_check_eoc(&p, len)) { expected_eoc--; if (expected_eoc == 0) break; len -= 2; continue; } q = p; /* Just read in a header: only care about the length */ if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, -1, 0, 0, NULL)) { ASN1err(ASN1_F_ASN1_FIND_END, ERR_R_NESTED_ASN1_ERROR); return 0; } if (inf) expected_eoc++; else p += plen; len -= p - q; } if (expected_eoc) { ASN1err(ASN1_F_ASN1_FIND_END, ASN1_R_MISSING_EOC); return 0; } *in = p; return 1; }
/* This function finds the end of an ASN1 structure when passed its maximum * length, whether it is indefinite length and a pointer to the content. * This is more efficient than calling asn1_collect because it does not * recurse on each indefinite length header. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/tasn_dec.c#L1089-L1137
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
asn1_check_eoc
static int asn1_check_eoc(const unsigned char **in, long len) { const unsigned char *p; if (len < 2) return 0; p = *in; if (!p[0] && !p[1]) { *in += 2; return 1; } return 0; }
/* Check for ASN1 EOC and swallow it if found */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/tasn_dec.c#L1239-L1250
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
asn1_check_tlen
static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst, const unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx) { int i; int ptag, pclass; long plen; const unsigned char *p, *q; p = *in; q = p; if (ctx && ctx->valid) { i = ctx->ret; plen = ctx->plen; pclass = ctx->pclass; ptag = ctx->ptag; p += ctx->hdrlen; } else { i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); if (ctx) { ctx->ret = i; ctx->plen = plen; ctx->pclass = pclass; ctx->ptag = ptag; ctx->hdrlen = p - q; ctx->valid = 1; /* If definite length, and no error, length + * header can't exceed total amount of data available. */ if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) { ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG); asn1_tlc_clear(ctx); return 0; } } } if (i & 0x80) { ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); asn1_tlc_clear(ctx); return 0; } if (exptag >= 0) { if ((exptag != ptag) || (expclass != pclass)) { /* If type is OPTIONAL, not an error: * indicate missing type. */ if (opt) return -1; asn1_tlc_clear(ctx); ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); return 0; } /* We have a tag and class match: * assume we are going to do something with it */ asn1_tlc_clear(ctx); } if (i & 1) plen = len - (p - q); if (inf) *inf = i & 1; if (cst) *cst = i & V_ASN1_CONSTRUCTED; if (olen) *olen = plen; if (oclass) *oclass = pclass; if (otag) *otag = ptag; *in = p; return 1; }
/* Check an ASN1 tag and length: a bit like ASN1_get_object * but it sets the length for indefinite length constructed * form, we don't know the exact length but we can set an * upper bound to the amount of data available minus the * header length just read. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/tasn_dec.c#L1259-L1347
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
ASN1_item_ndef_i2d
int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) { return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF); }
/* Top level i2d equivalents: the 'ndef' variant instructs the encoder * to use indefinite length constructed encoding, where appropriate */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/tasn_enc.c#L83-L87
4389085c8ce35cff887a4cc18fc47d1133d89ffb
BigWorld-Engine-14.4.1
github_2023
v2v3v4
c
asn1_item_flags_i2d
static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it, int flags) { if (out && !*out) { unsigned char *p, *buf; int len; len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); if (len <= 0) return len; buf = OPENSSL_malloc(len); if (!buf) return -1; p = buf; ASN1_item_ex_i2d(&val, &p, it, -1, flags); *out = buf; return len; } return ASN1_item_ex_i2d(&val, out, it, -1, flags); }
/* Encode an ASN1 item, this is use by the * standard 'i2d' function. 'out' points to * a buffer to output the data to. * * The new i2d has one additional feature. If the output * buffer is NULL (i.e. *out == NULL) then a buffer is * allocated and populated with the encoding. */
https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/asn1/tasn_enc.c#L103-L123
4389085c8ce35cff887a4cc18fc47d1133d89ffb