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 | nc_dn | static int nc_dn(X509_NAME *nm, X509_NAME *base)
{
/* Ensure canonical encodings are up to date. */
if (nm->modified && i2d_X509_NAME(nm, NULL) < 0)
return X509_V_ERR_OUT_OF_MEM;
if (base->modified && i2d_X509_NAME(base, NULL) < 0)
return X509_V_ERR_OUT_OF_MEM;
if (base->canon_enclen > nm->canon_enclen)
return X509_V_ERR_PERMITTED_VIOLATION;
if (memcmp(base->canon_enc, nm->canon_enc, base->canon_enclen))
return X509_V_ERR_PERMITTED_VIOLATION;
return X509_V_OK;
} | /* directoryName name constraint matching.
* The canonical encoding of X509_NAME makes this comparison easy. It is
* matched if the subtree is a subset of the name.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_ncons.c#L376-L388 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | i2r_ocsp_nocheck | static int i2r_ocsp_nocheck(const X509V3_EXT_METHOD *method, void *nocheck,
BIO *out, int indent)
{
return 1;
} | /* Nocheck is just a single NULL. Don't print anything and always set it */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_ocsp.c#L255-L259 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | X509V3_EXT_val_prn | void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, int ml)
{
int i;
CONF_VALUE *nval;
if(!val) return;
if(!ml || !sk_CONF_VALUE_num(val)) {
BIO_printf(out, "%*s", indent, "");
if(!sk_CONF_VALUE_num(val)) BIO_puts(out, "<EMPTY>\n");
}
for(i = 0; i < sk_CONF_VALUE_num(val); i++) {
if(ml) BIO_printf(out, "%*s", indent, "");
else if(i > 0) BIO_printf(out, ", ");
nval = sk_CONF_VALUE_value(val, i);
if(!nval->name) BIO_puts(out, nval->value);
else if(!nval->value) BIO_puts(out, nval->name);
#ifndef CHARSET_EBCDIC
else BIO_printf(out, "%s:%s", nval->name, nval->value);
#else
else {
int len;
char *tmp;
len = strlen(nval->value)+1;
tmp = OPENSSL_malloc(len);
if (tmp)
{
ascii2ebcdic(tmp, nval->value, len);
BIO_printf(out, "%s:%s", nval->name, tmp);
OPENSSL_free(tmp);
}
}
#endif
if(ml) BIO_puts(out, "\n");
}
} | /* Print out a name+value stack */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_prn.c#L71-L104 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | X509V3_EXT_print | int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int indent)
{
void *ext_str = NULL;
char *value = NULL;
const unsigned char *p;
const X509V3_EXT_METHOD *method;
STACK_OF(CONF_VALUE) *nval = NULL;
int ok = 1;
if(!(method = X509V3_EXT_get(ext)))
return unknown_ext_print(out, ext, flag, indent, 0);
p = ext->value->data;
if(method->it) ext_str = ASN1_item_d2i(NULL, &p, ext->value->length, ASN1_ITEM_ptr(method->it));
else ext_str = method->d2i(NULL, &p, ext->value->length);
if(!ext_str) return unknown_ext_print(out, ext, flag, indent, 1);
if(method->i2s) {
if(!(value = method->i2s(method, ext_str))) {
ok = 0;
goto err;
}
#ifndef CHARSET_EBCDIC
BIO_printf(out, "%*s%s", indent, "", value);
#else
{
int len;
char *tmp;
len = strlen(value)+1;
tmp = OPENSSL_malloc(len);
if (tmp)
{
ascii2ebcdic(tmp, value, len);
BIO_printf(out, "%*s%s", indent, "", tmp);
OPENSSL_free(tmp);
}
}
#endif
} else if(method->i2v) {
if(!(nval = method->i2v(method, ext_str, NULL))) {
ok = 0;
goto err;
}
X509V3_EXT_val_prn(out, nval, indent,
method->ext_flags & X509V3_EXT_MULTILINE);
} else if(method->i2r) {
if(!method->i2r(method, ext_str, out, indent)) ok = 0;
} else ok = 0;
err:
sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
if(value) OPENSSL_free(value);
if(method->it) ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it));
else method->ext_free(ext_str);
return ok;
} | /* Main routine: print out a general extension */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_prn.c#L108-L163 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | X509_check_purpose | int X509_check_purpose(X509 *x, int id, int ca)
{
int idx;
const X509_PURPOSE *pt;
if(!(x->ex_flags & EXFLAG_SET)) {
CRYPTO_w_lock(CRYPTO_LOCK_X509);
x509v3_cache_extensions(x);
CRYPTO_w_unlock(CRYPTO_LOCK_X509);
}
if(id == -1) return 1;
idx = X509_PURPOSE_get_by_id(id);
if(idx == -1) return -1;
pt = X509_PURPOSE_get0(idx);
return pt->check_purpose(pt, x, ca);
} | /* As much as I'd like to make X509_check_purpose use a "const" X509*
* I really can't because it does recalculate hashes and do other non-const
* things. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_purp.c#L109-L123 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | check_ssl_ca | static int check_ssl_ca(const X509 *x)
{
int ca_ret;
ca_ret = check_ca(x);
if(!ca_ret) return 0;
/* check nsCertType if present */
if(ca_ret != 5 || x->ex_nscert & NS_SSL_CA) return ca_ret;
else return 0;
} | /* Check SSL CA: common checks for SSL client and server */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_purp.c#L541-L549 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | purpose_smime | static int purpose_smime(const X509 *x, int ca)
{
if(xku_reject(x,XKU_SMIME)) return 0;
if(ca) {
int ca_ret;
ca_ret = check_ca(x);
if(!ca_ret) return 0;
/* check nsCertType if present */
if(ca_ret != 5 || x->ex_nscert & NS_SMIME_CA) return ca_ret;
else return 0;
}
if(x->ex_flags & EXFLAG_NSCERT) {
if(x->ex_nscert & NS_SMIME) return 1;
/* Workaround for some buggy certificates */
if(x->ex_nscert & NS_SSL_CLIENT) return 2;
return 0;
}
return 1;
} | /* common S/MIME checks */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_purp.c#L587-L605 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ocsp_helper | static int ocsp_helper(const X509_PURPOSE *xp, const X509 *x, int ca)
{
/* Must be a valid CA. Should we really support the "I don't know"
value (2)? */
if(ca) return check_ca(x);
/* leaf certificate is checked in OCSP_verify() */
return 1;
} | /* OCSP helper: this is *not* a full OCSP check. It just checks that
* each CA is valid. Additional checks must be made on the chain.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_purp.c#L640-L647 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | X509_check_issued | int X509_check_issued(X509 *issuer, X509 *subject)
{
if(X509_NAME_cmp(X509_get_subject_name(issuer),
X509_get_issuer_name(subject)))
return X509_V_ERR_SUBJECT_ISSUER_MISMATCH;
x509v3_cache_extensions(issuer);
x509v3_cache_extensions(subject);
if(subject->akid)
{
int ret = X509_check_akid(issuer, subject->akid);
if (ret != X509_V_OK)
return ret;
}
if(subject->ex_flags & EXFLAG_PROXY)
{
if(ku_reject(issuer, KU_DIGITAL_SIGNATURE))
return X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE;
}
else if(ku_reject(issuer, KU_KEY_CERT_SIGN))
return X509_V_ERR_KEYUSAGE_NO_CERTSIGN;
return X509_V_OK;
} | /* Various checks to see if one certificate issued the second.
* This can be used to prune a set of possible issuer certificates
* which have been looked up using some simple method such as by
* subject name.
* These are:
* 1. Check issuer_name(subject) == subject_name(issuer)
* 2. If akid(subject) exists check it matches issuer
* 3. If key_usage(issuer) exists check it supports certificate signing
* returns 0 for OK, positive for reason for mismatch, reasons match
* codes for X509_verify_cert()
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_purp.c#L701-L724 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SXNET_add_id_asc | int SXNET_add_id_asc(SXNET **psx, char *zone, char *user,
int userlen)
{
ASN1_INTEGER *izone = NULL;
if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
X509V3err(X509V3_F_SXNET_ADD_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
return 0;
}
return SXNET_add_id_INTEGER(psx, izone, user, userlen);
} | /* Strong Extranet utility functions */
/* Add an id given the zone as an ASCII number */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_sxnet.c#L152-L161 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SXNET_add_id_ulong | int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
int userlen)
{
ASN1_INTEGER *izone = NULL;
if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) {
X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE);
M_ASN1_INTEGER_free(izone);
return 0;
}
return SXNET_add_id_INTEGER(psx, izone, user, userlen);
} | /* Add an id given the zone as an unsigned long */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_sxnet.c#L165-L176 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SXNET_add_id_INTEGER | int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,
int userlen)
{
SXNET *sx = NULL;
SXNETID *id = NULL;
if(!psx || !zone || !user) {
X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_INVALID_NULL_ARGUMENT);
return 0;
}
if(userlen == -1) userlen = strlen(user);
if(userlen > 64) {
X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_USER_TOO_LONG);
return 0;
}
if(!*psx) {
if(!(sx = SXNET_new())) goto err;
if(!ASN1_INTEGER_set(sx->version, 0)) goto err;
*psx = sx;
} else sx = *psx;
if(SXNET_get_id_INTEGER(sx, zone)) {
X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_DUPLICATE_ZONE_ID);
return 0;
}
if(!(id = SXNETID_new())) goto err;
if(userlen == -1) userlen = strlen(user);
if(!M_ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err;
if(!sk_SXNETID_push(sx->ids, id)) goto err;
id->zone = zone;
return 1;
err:
X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,ERR_R_MALLOC_FAILURE);
SXNETID_free(id);
SXNET_free(sx);
*psx = NULL;
return 0;
} | /* Add an id given the zone as an ASN1_INTEGER.
* Note this version uses the passed integer and doesn't make a copy so don't
* free it up afterwards.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_sxnet.c#L183-L221 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | X509V3_add_value | int X509V3_add_value(const char *name, const char *value,
STACK_OF(CONF_VALUE) **extlist)
{
CONF_VALUE *vtmp = NULL;
char *tname = NULL, *tvalue = NULL;
if(name && !(tname = BUF_strdup(name))) goto err;
if(value && !(tvalue = BUF_strdup(value))) goto err;
if(!(vtmp = (CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) goto err;
if(!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) goto err;
vtmp->section = NULL;
vtmp->name = tname;
vtmp->value = tvalue;
if(!sk_CONF_VALUE_push(*extlist, vtmp)) goto err;
return 1;
err:
X509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE);
if(vtmp) OPENSSL_free(vtmp);
if(tname) OPENSSL_free(tname);
if(tvalue) OPENSSL_free(tvalue);
return 0;
} | /* Add a CONF_VALUE name value pair to stack */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_utl.c#L81-L101 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | X509V3_conf_free | void X509V3_conf_free(CONF_VALUE *conf)
{
if(!conf) return;
if(conf->name) OPENSSL_free(conf->name);
if(conf->value) OPENSSL_free(conf->value);
if(conf->section) OPENSSL_free(conf->section);
OPENSSL_free(conf);
} | /* Free function for STACK_OF(CONF_VALUE) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_utl.c#L111-L118 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | name_cmp | int name_cmp(const char *name, const char *cmp)
{
int len, ret;
char c;
len = strlen(cmp);
if((ret = strncmp(name, cmp, len))) return ret;
c = name[len];
if(!c || (c=='.')) return 0;
return 1;
} | /* V2I name comparison function: returns zero if 'name' matches
* cmp or cmp.*
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_utl.c#L450-L459 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ipv6_hex | static int ipv6_hex(unsigned char *out, const char *in, int inlen)
{
unsigned char c;
unsigned int num = 0;
if (inlen > 4)
return 0;
while(inlen--)
{
c = *in++;
num <<= 4;
if ((c >= '0') && (c <= '9'))
num |= c - '0';
else if ((c >= 'A') && (c <= 'F'))
num |= c - 'A' + 10;
else if ((c >= 'a') && (c <= 'f'))
num |= c - 'a' + 10;
else
return 0;
}
out[0] = num >> 8;
out[1] = num & 0xff;
return 1;
} | /* Convert a string of up to 4 hex digits into the corresponding
* IPv6 form.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3_utl.c#L805-L827 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | main | int main(int argc, char **argv)
{
LHASH *conf;
X509 *cert;
FILE *inf;
char *conf_file;
int i;
int count;
X509_EXTENSION *ext;
X509V3_add_standard_extensions();
ERR_load_crypto_strings();
if(!argv[1]) {
fprintf(stderr, "Usage: v3conf cert.pem [file.cnf]\n");
exit(1);
}
conf_file = argv[2];
if(!conf_file) conf_file = "test.cnf";
conf = CONF_load(NULL, "test.cnf", NULL);
if(!conf) {
fprintf(stderr, "Error opening Config file %s\n", conf_file);
ERR_print_errors_fp(stderr);
exit(1);
}
inf = fopen(argv[1], "r");
if(!inf) {
fprintf(stderr, "Can't open certificate file %s\n", argv[1]);
exit(1);
}
cert = PEM_read_X509(inf, NULL, NULL);
if(!cert) {
fprintf(stderr, "Error reading certificate file %s\n", argv[1]);
exit(1);
}
fclose(inf);
sk_pop_free(cert->cert_info->extensions, X509_EXTENSION_free);
cert->cert_info->extensions = NULL;
if(!X509V3_EXT_add_conf(conf, NULL, "test_section", cert)) {
fprintf(stderr, "Error adding extensions\n");
ERR_print_errors_fp(stderr);
exit(1);
}
count = X509_get_ext_count(cert);
printf("%d extensions\n", count);
for(i = 0; i < count; i++) {
ext = X509_get_ext(cert, i);
printf("%s", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
if(ext->critical) printf(",critical:\n");
else printf(":\n");
X509V3_EXT_print_fp(stdout, ext, 0, 0);
printf("\n");
}
return 0;
} | /* Test application to add extensions from a config file */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/x509v3/v3conf.c#L69-L126 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | EVP_PKEY_assign | int EVP_PKEY_assign(pkey,type,key)
EVP_PKEY *pkey;
int type;
char *key;
{
if (pkey == NULL) return(0);
if (pkey->pkey.ptr != NULL)
{
if (pkey->type == EVP_PKEY_RSA)
RSA_free(pkey->pkey.rsa);
/* else memory leak */
}
pkey->type=type;
pkey->pkey.ptr=key;
return(1);
} | /* This function is in the next version of SSLeay */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/spkigen.c#L93-L108 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | SPKI_set_pubkey | int SPKI_set_pubkey(x,pkey)
NETSCAPE_SPKI *x;
EVP_PKEY *pkey;
{
int ok=0;
X509_PUBKEY *pk;
X509_ALGOR *a;
ASN1_OBJECT *o;
unsigned char *s,*p;
int i;
if (x == NULL) return(0);
if ((pk=X509_PUBKEY_new()) == NULL) goto err;
a=pk->algor;
/* set the algorithm id */
if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err;
ASN1_OBJECT_free(a->algorithm);
a->algorithm=o;
/* Set the parameter list */
if ((a->parameter == NULL) || (a->parameter->type != V_ASN1_NULL))
{
ASN1_TYPE_free(a->parameter);
a->parameter=ASN1_TYPE_new();
a->parameter->type=V_ASN1_NULL;
}
i=i2d_PublicKey(pkey,NULL);
if ((s=(unsigned char *)malloc(i+1)) == NULL) goto err;
p=s;
i2d_PublicKey(pkey,&p);
if (!ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;
free(s);
X509_PUBKEY_free(x->spkac->pubkey);
x->spkac->pubkey=pk;
pk=NULL;
ok=1;
err:
if (pk != NULL) X509_PUBKEY_free(pk);
return(ok);
} | /* While I have a
* X509_set_pubkey() and X509_REQ_set_pubkey(), SPKI_set_pubkey() does
* not currently exist so here is a version of it.
* The next SSLeay release will probably have
* X509_set_pubkey(),
* X509_REQ_set_pubkey() and
* NETSCAPE_SPKI_set_pubkey()
* as macros calling the same function */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/spkigen.c#L118-L160 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | tls_start_proxy | int
tls_start_proxy(struct tls_start_proxy_args a, void *apparg)
{
int fds[2] = {-1, -1};
int infofds[2] = {-1, -1};
int r, getfd, getfl;
int ret;
DEBUG_MSG2("tls_start_proxy fd", a.fd);
DEBUG_MSG2("tls_start_proxy client_p", a.client_p);
if (a.fd == -1 || a.client_p == -1 || a.ctx == NULL)
return 1;
if (a.pid != NULL) {
*a.pid = 0;
}
if (a.infofd != NULL) {
*a.infofd = -1;
}
r = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
if (r == -1)
return -1;
if (a.fd >= FD_SETSIZE || fds[0] >= FD_SETSIZE) {
ret = 2;
goto err;
}
if (a.infofd != NULL) {
r = pipe(infofds);
if (r == -1) {
ret = -3;
goto err;
}
}
r = fork();
if (r == -1) {
ret = -4;
goto err;
}
if (r == 0) {
DEBUG_MSG("fork");
tls_child_p = 1;
tls_child_apparg = apparg;
close(fds[1]);
if (infofds[0] != -1)
close(infofds[0]);
TLS_APP_PROCESS_INIT(a.fd, a.client_p, apparg);
DEBUG_MSG("TLS_APP_PROCESS_INIT");
tls_proxy(fds[0], a.fd, infofds[1], a.ctx, a.client_p);
exit(0);
}
if (a.pid != NULL)
*a.pid = r;
if (infofds[1] != -1) {
close(infofds[1]);
infofds[1] = -1;
}
/* install fds[1] in place of fd: */
close(fds[0]);
fds[0] = -1;
getfd = fcntl(a.fd, F_GETFD);
getfl = fcntl(a.fd, F_GETFL);
r = dup2(fds[1], a.fd);
close(fds[1]);
fds[1] = -1;
if (r == -1) {
ret = -5;
goto err;
}
if (getfd != 1)
fcntl(a.fd, F_SETFD, getfd);
if (getfl & O_NONBLOCK)
(void)tls_socket_nonblocking(a.fd);
if (a.infofd != NULL)
*a.infofd = infofds[0];
return 0;
err:
if (fds[0] != -1)
close(fds[0]);
if (fds[1] != -1)
close(fds[1]);
if (infofds[0] != -1)
close(infofds[0]);
if (infofds[1] != -1)
close(infofds[1]);
return ret;
} | /* Slice in TLS proxy process at fd.
* Return value:
* 0 ok (*pid is set to child's PID if pid != NULL),
* < 0 look at errno
* > 0 other error
* (return value encodes place of error)
*
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/easy_tls/easy-tls.c#L196-L285 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | tls_rand_seed_uniquely | static void
tls_rand_seed_uniquely(void)
{
struct {
pid_t pid;
time_t time;
void *stack;
} data;
data.pid = getpid();
data.time = time(NULL);
data.stack = (void *)&data;
RAND_seed((const void *)&data, sizeof data);
} | /*****************************************************************************/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/easy_tls/easy-tls.c#L426-L440 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | no_passphrase_callback | static int
no_passphrase_callback(char *buf, int num, int w, void *arg)
{
return -1;
} | /*****************************************************************************/
/* to hinder OpenSSL from asking for passphrases */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/easy_tls/easy-tls.c#L564-L568 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | tls_set_dhe1024 | void
tls_set_dhe1024(int i, void *apparg)
{
DSA *dsaparams;
DH *dhparams;
const char *seed[] = { ";-) :-( :-) :-( ",
";-) :-( :-) :-( ",
"Random String no. 12",
";-) :-( :-) :-( ",
"hackers have even mo", /* from jargon file */
};
unsigned char seedbuf[20];
tls_init(apparg);
if (i >= 0) {
i %= sizeof seed / sizeof seed[0];
assert(strlen(seed[i]) == 20);
memcpy(seedbuf, seed[i], 20);
dsaparams = DSA_generate_parameters(1024, seedbuf, 20, NULL, NULL, 0, NULL);
} else {
/* random parameters (may take a while) */
dsaparams = DSA_generate_parameters(1024, NULL, 0, NULL, NULL, 0, NULL);
}
if (dsaparams == NULL) {
tls_openssl_errors("", "", NULL, apparg);
return;
}
dhparams = DSA_dup_DH(dsaparams);
DSA_free(dsaparams);
if (dhparams == NULL) {
tls_openssl_errors("", "", NULL, apparg);
return;
}
if (tls_dhe1024 != NULL)
DH_free(tls_dhe1024);
tls_dhe1024 = dhparams;
} | /* generating these takes a while, so do it just once */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/easy_tls/easy-tls.c#L595-L632 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | tls_socket_nonblocking | static int
tls_socket_nonblocking(int fd)
{
int v, r;
v = fcntl(fd, F_GETFL, 0);
if (v == -1) {
if (errno == EINVAL)
return 0; /* already shut down -- ignore */
return -1;
}
r = fcntl(fd, F_SETFL, v | O_NONBLOCK);
if (r == -1) {
if (errno == EINVAL)
return 0; /* already shut down -- ignore */
return -1;
}
return 0;
} | /*****************************************************************************/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/easy_tls/easy-tls.c#L784-L802 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | tls_proxy | static void
tls_proxy(int clear_fd, int tls_fd, int info_fd, SSL_CTX *ctx, int client_p)
{
struct tunnelbuf clear_to_tls, tls_to_clear;
SSL *ssl;
BIO *rbio, *wbio;
int closed, in_handshake;
const char *err_pref_1 = "", *err_pref_2 = "";
const char *err_def = NULL;
assert(clear_fd != -1);
assert(tls_fd != -1);
assert(clear_fd < FD_SETSIZE);
assert(tls_fd < FD_SETSIZE);
/* info_fd may be -1 */
assert(ctx != NULL);
tls_rand_seed_uniquely();
tls_socket_nonblocking(clear_fd);
DEBUG_MSG2("clear_fd", clear_fd);
tls_socket_nonblocking(tls_fd);
DEBUG_MSG2("tls_fd", tls_fd);
ssl = SSL_new(ctx);
if (ssl == NULL)
goto err;
DEBUG_MSG("SSL_new");
if (!SSL_set_fd(ssl, tls_fd))
goto err;
rbio = SSL_get_rbio(ssl);
wbio = SSL_get_wbio(ssl); /* should be the same, but who cares */
assert(rbio != NULL);
assert(wbio != NULL);
if (client_p)
SSL_set_connect_state(ssl);
else
SSL_set_accept_state(ssl);
closed = 0;
in_handshake = 1;
tls_to_clear.len = 0;
tls_to_clear.offset = 0;
clear_to_tls.len = 0;
clear_to_tls.offset = 0;
err_def = "I/O error";
/* loop finishes as soon as we detect that one side closed;
* when all (program and OS) buffers have enough space,
* the data from the last succesful read in each direction is transferred
* before close */
do {
int clear_read_select = 0, clear_write_select = 0,
tls_read_select = 0, tls_write_select = 0,
progress = 0;
int r;
unsigned long num_read = BIO_number_read(rbio),
num_written = BIO_number_written(wbio);
DEBUG_MSG2("loop iteration", ++tls_loop_count);
if (in_handshake) {
DEBUG_MSG("in_handshake");
if (client_p)
r = tls_connect_attempt(ssl, &tls_write_select, &tls_read_select, &closed, &progress, &err_pref_1);
else
r = tls_accept_attempt(ssl, &tls_write_select, &tls_read_select, &closed, &progress, &err_pref_1);
if (r != 0) {
write_info(ssl, &info_fd);
goto err;
}
if (closed)
goto err_return;
if (!SSL_in_init(ssl)) {
in_handshake = 0;
write_info(ssl, &info_fd);
}
}
if (clear_to_tls.len != 0 && !in_handshake) {
assert(!closed);
r = tls_write_attempt(ssl, &clear_to_tls, &tls_write_select, &tls_read_select, &closed, &progress, &err_pref_1);
if (r != 0)
goto err;
if (closed) {
assert(progress);
tls_to_clear.offset = 0;
tls_to_clear.len = 0;
}
}
if (tls_to_clear.len != 0) {
assert(!closed);
r = write_attempt(clear_fd, &tls_to_clear, &clear_write_select, &closed, &progress);
if (r != 0)
goto err_return;
if (closed) {
assert(progress);
clear_to_tls.offset = 0;
clear_to_tls.len = 0;
}
}
if (!closed) {
if (clear_to_tls.offset + clear_to_tls.len < sizeof clear_to_tls.buf) {
r = read_attempt(clear_fd, &clear_to_tls, &clear_read_select, &closed, &progress);
if (r != 0)
goto err_return;
if (closed) {
r = SSL_shutdown(ssl);
DEBUG_MSG2("SSL_shutdown", r);
}
}
}
if (!closed && !in_handshake) {
if (tls_to_clear.offset + tls_to_clear.len < sizeof tls_to_clear.buf) {
r = tls_read_attempt(ssl, &tls_to_clear, &tls_write_select, &tls_read_select, &closed, &progress, &err_pref_1);
if (r != 0)
goto err;
if (closed) {
r = SSL_shutdown(ssl);
DEBUG_MSG2("SSL_shutdown", r);
}
}
}
if (!progress) {
DEBUG_MSG("!progress?");
if (num_read != BIO_number_read(rbio) || num_written != BIO_number_written(wbio))
progress = 1;
if (!progress) {
DEBUG_MSG("!progress");
assert(clear_read_select || tls_read_select || clear_write_select || tls_write_select);
tls_sockets_select(clear_read_select ? clear_fd : -1, tls_read_select ? tls_fd : -1, clear_write_select ? clear_fd : -1, tls_write_select ? tls_fd : -1, -1);
}
}
} while (!closed);
return;
err:
tls_openssl_errors(err_pref_1, err_pref_2, err_def, tls_child_apparg);
err_return:
return;
} | /* tls_proxy expects that all fds are closed after return */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/easy_tls/easy-tls.c#L924-L1072 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | callback | void callback(stage,count,arg)
int stage,count;
char *arg;
{
FILE *out;
out=(FILE *)arg;
fprintf(out,"%d",stage);
if (stage == 3)
fprintf(out,"\n");
fflush(out);
} | /* This is a simple program to generate an RSA private key. It then
* saves both the public and private key into a char array, then
* re-reads them. It saves them as DER encoded binary data.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/eay/loadrsa.c#L9-L20 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | bind_helper | static int bind_helper(ENGINE *e)
{
if(!ENGINE_set_id(e, engine_cluster_labs_id) ||
!ENGINE_set_name(e, engine_cluster_labs_name) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_RSA(e, &cluster_labs_rsa) ||
#endif
#ifndef OPENSSL_NO_DSA
!ENGINE_set_DSA(e, &cluster_labs_dsa) ||
#endif
#ifndef OPENSSL_NO_DH
!ENGINE_set_DH(e, &cluster_labs_dh) ||
#endif
!ENGINE_set_RAND(e, &cluster_labs_rand) ||
!ENGINE_set_destroy_function(e, cluster_labs_destroy) ||
!ENGINE_set_init_function(e, cluster_labs_init) ||
!ENGINE_set_finish_function(e, cluster_labs_finish) ||
!ENGINE_set_ctrl_function(e, cluster_labs_ctrl) ||
!ENGINE_set_cmd_defns(e, cluster_labs_cmd_defns))
return 0;
/* Ensure the error handling is set up */
ERR_load_CL_strings();
return 1;
} | /* engine implementation */
/*-----------------------*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/cluster_labs/hw_cluster_labs.c#L207-L231 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | cluster_labs_destroy | static int cluster_labs_destroy(ENGINE *e)
{
ERR_unload_CL_strings();
return 1;
} | /* !ENGINE_DYNAMIC_SUPPORT */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/cluster_labs/hw_cluster_labs.c#L263-L268 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | cluster_labs_mod_exp_mont | static int cluster_labs_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
{
return cluster_labs_mod_exp(r, a, p, m, ctx);
} | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/cluster_labs/hw_cluster_labs.c#L578-L582 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | cluster_labs_mod_exp_dh | static int cluster_labs_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
{
return cluster_labs_mod_exp(r, a, p, m, ctx);
} | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/cluster_labs/hw_cluster_labs.c#L586-L590 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | cluster_labs_rand_bytes | static int cluster_labs_rand_bytes(unsigned char *buf, int num){
if(cluster_labs_dso == NULL)
{
CLerr(CL_F_CLUSTER_LABS_RAND_BYTES,CL_R_NOT_LOADED);
return 0;
}
if(p_cl_mod_exp_crt == NULL)
{
CLerr(CL_F_CLUSTER_LABS_RAND_BYTES,CL_R_FUNCTION_NOT_BINDED);
return 0;
}
return p_cl_rand_bytes(buf, num);
} | /************************************************************************************
* Symmetric algorithms
************************************************************************************/
/* this will be come soon! */
/************************************************************************************
* Random generator
************************************************************************************/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/cluster_labs/hw_cluster_labs.c#L680-L695 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | bind_helper | static int bind_helper(ENGINE *e)
{
#ifndef OPENSSL_NO_RSA
const RSA_METHOD *meth1;
#endif
#ifndef OPENSSL_NO_DSA
const DSA_METHOD *meth2;
#endif
#ifndef OPENSSL_NO_DH
const DH_METHOD *meth3;
#endif
if(!ENGINE_set_id(e, engine_ibmca_id) ||
!ENGINE_set_name(e, engine_ibmca_name) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_RSA(e, &ibmca_rsa) ||
#endif
#ifndef OPENSSL_NO_DSA
!ENGINE_set_DSA(e, &ibmca_dsa) ||
#endif
#ifndef OPENSSL_NO_DH
!ENGINE_set_DH(e, &ibmca_dh) ||
#endif
!ENGINE_set_RAND(e, &ibmca_rand) ||
!ENGINE_set_destroy_function(e, ibmca_destroy) ||
!ENGINE_set_init_function(e, ibmca_init) ||
!ENGINE_set_finish_function(e, ibmca_finish) ||
!ENGINE_set_ctrl_function(e, ibmca_ctrl) ||
!ENGINE_set_cmd_defns(e, ibmca_cmd_defns))
return 0;
#ifndef OPENSSL_NO_RSA
/* We know that the "PKCS1_SSLeay()" functions hook properly
* to the ibmca-specific mod_exp and mod_exp_crt so we use
* those functions. NB: We don't use ENGINE_openssl() or
* anything "more generic" because something like the RSAref
* code may not hook properly, and if you own one of these
* cards then you have the right to do RSA operations on it
* anyway! */
meth1 = RSA_PKCS1_SSLeay();
ibmca_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
ibmca_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
ibmca_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
ibmca_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
#endif
#ifndef OPENSSL_NO_DSA
/* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
* bits. */
meth2 = DSA_OpenSSL();
ibmca_dsa.dsa_do_sign = meth2->dsa_do_sign;
ibmca_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
ibmca_dsa.dsa_do_verify = meth2->dsa_do_verify;
#endif
#ifndef OPENSSL_NO_DH
/* Much the same for Diffie-Hellman */
meth3 = DH_OpenSSL();
ibmca_dh.generate_key = meth3->generate_key;
ibmca_dh.compute_key = meth3->compute_key;
#endif
/* Ensure the ibmca error handling is set up */
ERR_load_IBMCA_strings();
return 1;
} | /* This internal function is used by ENGINE_ibmca() and possibly by the
* "dynamic" ENGINE support too */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L212-L276 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ibmca_destroy | static int ibmca_destroy(ENGINE *e)
{
/* Unload the ibmca error strings so any error state including our
* functs or reasons won't lead to a segfault (they simply get displayed
* without corresponding string data because none will be found). */
ERR_unload_IBMCA_strings();
return 1;
} | /* Destructor (complements the "ENGINE_ibmca()" constructor) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L305-L312 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_context | static int get_context(ICA_ADAPTER_HANDLE *p_handle)
{
unsigned int status=0;
status = p_icaOpenAdapter(0, p_handle);
if(status != 0)
return 0;
return 1;
} | /* utility function to obtain a context */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L333-L341 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | release_context | static void release_context(ICA_ADAPTER_HANDLE handle)
{
p_icaCloseAdapter(handle);
} | /* similarly to release one. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L344-L347 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ibmca_init | static int ibmca_init(ENGINE *e)
{
void (*p1)();
void (*p2)();
void (*p3)();
void (*p4)();
void (*p5)();
if(ibmca_dso != NULL)
{
IBMCAerr(IBMCA_F_IBMCA_INIT,IBMCA_R_ALREADY_LOADED);
goto err;
}
/* Attempt to load libatasi.so/atasi.dll/whatever. Needs to be
* changed unfortunately because the Ibmca drivers don't have
* standard library names that can be platform-translated well. */
/* TODO: Work out how to actually map to the names the Ibmca
* drivers really use - for now a symbollic link needs to be
* created on the host system from libatasi.so to atasi.so on
* unix variants. */
/* WJH XXX check name translation */
ibmca_dso = DSO_load(NULL, IBMCA_LIBNAME, NULL,
/* DSO_FLAG_NAME_TRANSLATION */ 0);
if(ibmca_dso == NULL)
{
IBMCAerr(IBMCA_F_IBMCA_INIT,IBMCA_R_DSO_FAILURE);
goto err;
}
if(!(p1 = DSO_bind_func(
ibmca_dso, IBMCA_F1)) ||
!(p2 = DSO_bind_func(
ibmca_dso, IBMCA_F2)) ||
!(p3 = DSO_bind_func(
ibmca_dso, IBMCA_F3)) ||
!(p4 = DSO_bind_func(
ibmca_dso, IBMCA_F4)) ||
!(p5 = DSO_bind_func(
ibmca_dso, IBMCA_F5)))
{
IBMCAerr(IBMCA_F_IBMCA_INIT,IBMCA_R_DSO_FAILURE);
goto err;
}
/* Copy the pointers */
p_icaOpenAdapter = (unsigned int (ICA_CALL *)())p1;
p_icaCloseAdapter = (unsigned int (ICA_CALL *)())p2;
p_icaRsaModExpo = (unsigned int (ICA_CALL *)())p3;
p_icaRandomNumberGenerate = (unsigned int (ICA_CALL *)())p4;
p_icaRsaCrt = (unsigned int (ICA_CALL *)())p5;
if(!get_context(&handle))
{
IBMCAerr(IBMCA_F_IBMCA_INIT,IBMCA_R_UNIT_FAILURE);
goto err;
}
return 1;
err:
if(ibmca_dso)
DSO_free(ibmca_dso);
p_icaOpenAdapter = NULL;
p_icaCloseAdapter = NULL;
p_icaRsaModExpo = NULL;
p_icaRandomNumberGenerate = NULL;
return 0;
} | /* (de)initialisation functions. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L350-L422 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ibmca_mod_exp_crt | static int ibmca_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *q, const BIGNUM *dmp1,
const BIGNUM *dmq1, const BIGNUM *iqmp, BN_CTX *ctx)
{
BIGNUM *argument = NULL;
BIGNUM *result = NULL;
BIGNUM *key = NULL;
int to_return = 0; /* expect failure */
char *pkey=NULL;
ICA_KEY_RSA_CRT *privKey=NULL;
int inLen, outLen;
int rc;
unsigned int offset, pSize, qSize;
/* SAB New variables */
unsigned int keyRecordSize;
unsigned int pbytes = BN_num_bytes(p);
unsigned int qbytes = BN_num_bytes(q);
unsigned int dmp1bytes = BN_num_bytes(dmp1);
unsigned int dmq1bytes = BN_num_bytes(dmq1);
unsigned int iqmpbytes = BN_num_bytes(iqmp);
/* Prepare the params */
BN_CTX_start(ctx);
argument = BN_CTX_get(ctx);
result = BN_CTX_get(ctx);
key = BN_CTX_get(ctx);
if(!argument || !result || !key)
{
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT,IBMCA_R_BN_CTX_FULL);
goto err;
}
if(!bn_wexpand(argument, p->top + q->top) ||
!bn_wexpand(result, p->top + q->top) ||
!bn_wexpand(key, sizeof(*privKey)/BN_BYTES ))
{
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT,IBMCA_R_BN_EXPAND_FAIL);
goto err;
}
privKey = (ICA_KEY_RSA_CRT *)key->d;
/* SAB Add check for total size in bytes of the parms does not exceed
the buffer space we have
do this first
*/
keyRecordSize = pbytes+qbytes+dmp1bytes+dmq1bytes+iqmpbytes;
if ( keyRecordSize > sizeof(privKey->keyRecord )) {
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT,IBMCA_R_OPERANDS_TO_LARGE);
goto err;
}
if ( (qbytes + dmq1bytes) > 256 ){
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT,IBMCA_R_OPERANDS_TO_LARGE);
goto err;
}
if ( pbytes + dmp1bytes > 256 ) {
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT,IBMCA_R_OPERANDS_TO_LARGE);
goto err;
}
/* end SAB additions */
memset(privKey, 0, sizeof(ICA_KEY_RSA_CRT));
privKey->keyType = CORRECT_ENDIANNESS(CRT_KEY_TYPE);
privKey->keyLength = CORRECT_ENDIANNESS(sizeof(ICA_KEY_RSA_CRT));
privKey->modulusBitLength =
CORRECT_ENDIANNESS(BN_num_bytes(q) * 2 * 8);
/*
* p,dp & qInv are 1 QWORD Larger
*/
privKey->pLength = CORRECT_ENDIANNESS(BN_num_bytes(p)+8);
privKey->qLength = CORRECT_ENDIANNESS(BN_num_bytes(q));
privKey->dpLength = CORRECT_ENDIANNESS(BN_num_bytes(dmp1)+8);
privKey->dqLength = CORRECT_ENDIANNESS(BN_num_bytes(dmq1));
privKey->qInvLength = CORRECT_ENDIANNESS(BN_num_bytes(iqmp)+8);
offset = (char *) privKey->keyRecord
- (char *) privKey;
qSize = BN_num_bytes(q);
pSize = qSize + 8; /* 1 QWORD larger */
/* SAB probably aittle redundant, but we'll verify that each of the
components which make up a key record sent ot the card does not exceed
the space that is allocated for it. this handles the case where even if
the total length does not exceed keyrecord zied, if the operands are funny sized
they could cause potential side affects on either the card or the result */
if ( (pbytes > pSize) || (dmp1bytes > pSize) ||
(iqmpbytes > pSize) || ( qbytes >qSize) ||
(dmq1bytes > qSize) ) {
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT, IBMCA_R_OPERANDS_TO_LARGE);
goto err;
}
privKey->dpOffset = CORRECT_ENDIANNESS(offset);
offset += pSize;
privKey->dqOffset = CORRECT_ENDIANNESS(offset);
offset += qSize;
privKey->pOffset = CORRECT_ENDIANNESS(offset);
offset += pSize;
privKey->qOffset = CORRECT_ENDIANNESS(offset);
offset += qSize;
privKey->qInvOffset = CORRECT_ENDIANNESS(offset);
pkey = (char *) privKey->keyRecord;
/* SAB first check that we don;t under flow the buffer */
if ( pSize < pbytes ) {
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT, IBMCA_R_UNDERFLOW_CONDITION);
goto err;
}
/* pkey += pSize - BN_num_bytes(p); WROING this should be dmp1) */
pkey += pSize - BN_num_bytes(dmp1);
BN_bn2bin(dmp1, pkey);
pkey += BN_num_bytes(dmp1); /* move the pointer */
BN_bn2bin(dmq1, pkey); /* Copy over dmq1 */
pkey += qSize; /* move pointer */
pkey += pSize - BN_num_bytes(p); /* set up for zero padding of next field */
BN_bn2bin(p, pkey);
pkey += BN_num_bytes(p); /* increment pointer by number of bytes moved */
BN_bn2bin(q, pkey);
pkey += qSize ; /* move the pointer */
pkey += pSize - BN_num_bytes(iqmp); /* Adjust for padding */
BN_bn2bin(iqmp, pkey);
/* Prepare the argument and response */
outLen = CORRECT_ENDIANNESS(privKey->qLength) * 2; /* Correct endianess is used
because the fields were converted above */
if (outLen > 256) {
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT,IBMCA_R_OUTLEN_TO_LARGE);
goto err;
}
/* SAB check for underflow here on the argeument */
if ( outLen < BN_num_bytes(a)) {
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT,IBMCA_R_UNDERFLOW_CONDITION);
goto err;
}
BN_bn2bin(a, (unsigned char *)argument->d + outLen -
BN_num_bytes(a));
inLen = outLen;
memset(result->d, 0, outLen);
/* Perform the operation */
if ( (rc = p_icaRsaCrt(handle, inLen, (unsigned char *)argument->d,
privKey, &outLen, (unsigned char *)result->d)) != 0)
{
printf("rc = %d\n", rc);
IBMCAerr(IBMCA_F_IBMCA_MOD_EXP_CRT,IBMCA_R_REQUEST_FAILED);
goto err;
}
/* Convert the response */
BN_bin2bn((unsigned char *)result->d, outLen, r);
to_return = 1;
err:
BN_CTX_end(ctx);
return to_return;
} | /* Ein kleines chinesisches "Restessen" */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L629-L818 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ibmca_dsa_mod_exp | static int ibmca_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
BN_CTX *ctx, BN_MONT_CTX *in_mont)
{
BIGNUM t;
int to_return = 0;
BN_init(&t);
/* let rr = a1 ^ p1 mod m */
if (!ibmca_mod_exp(rr,a1,p1,m,ctx)) goto end;
/* let t = a2 ^ p2 mod m */
if (!ibmca_mod_exp(&t,a2,p2,m,ctx)) goto end;
/* let rr = rr * t mod m */
if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
to_return = 1;
end:
BN_free(&t);
return to_return;
} | /* This code was liberated and adapted from the commented-out code in
* dsa_ossl.c. Because of the unoptimised form of the Ibmca acceleration
* (it doesn't have a CRT form for RSA), this function means that an
* Ibmca system running with a DSA server certificate can handshake
* around 5 or 6 times faster/more than an equivalent system running with
* RSA. Just check out the "signs" statistics from the RSA and DSA parts
* of "openssl speed -engine ibmca dsa1024 rsa1024". */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L828-L846 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ibmca_mod_exp_mont | static int ibmca_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
{
return ibmca_mod_exp(r, a, p, m, ctx);
} | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L858-L862 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ibmca_mod_exp_dh | static int ibmca_mod_exp_dh(DH const *dh, BIGNUM *r,
const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
{
return ibmca_mod_exp(r, a, p, m, ctx);
} | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L866-L871 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ibmca_rand_bytes | static int ibmca_rand_bytes(unsigned char *buf, int num)
{
int to_return = 0; /* assume failure */
unsigned int ret;
if(handle == 0)
{
IBMCAerr(IBMCA_F_IBMCA_RAND_BYTES,IBMCA_R_NOT_INITIALISED);
goto err;
}
ret = p_icaRandomNumberGenerate(handle, num, buf);
if (ret < 0)
{
IBMCAerr(IBMCA_F_IBMCA_RAND_BYTES,IBMCA_R_REQUEST_FAILED);
goto err;
}
to_return = 1;
err:
return to_return;
} | /* Random bytes are good */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/ibmca/hw_ibmca.c#L875-L896 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | bind_rsaref | static int bind_rsaref(ENGINE *e)
{
const RSA_METHOD *meth1;
if(!ENGINE_set_id(e, engine_rsaref_id)
|| !ENGINE_set_name(e, engine_rsaref_name)
|| !ENGINE_set_RSA(e, &rsaref_rsa)
|| !ENGINE_set_ciphers(e, rsaref_ciphers)
|| !ENGINE_set_digests(e, rsaref_digests)
|| !ENGINE_set_destroy_function(e, rsaref_destroy)
|| !ENGINE_set_init_function(e, rsaref_init)
|| !ENGINE_set_finish_function(e, rsaref_finish)
/* || !ENGINE_set_ctrl_function(e, rsaref_ctrl) */
/* || !ENGINE_set_cmd_defns(e, rsaref_cmd_defns) */)
return 0;
/* Ensure the rsaref error handling is set up */
ERR_load_RSAREF_strings();
return 1;
} | /*****************************************************************************
*** Function definitions ***
*****************************************************************************/
/*****************************************************************************
* Functions to handle the engine
**/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/rsaref/rsaref.c#L218-L236 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | rsaref_init | static int rsaref_init(ENGINE *e)
{
return 1;
} | /* Initiator which is only present to make sure this engine looks available */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/rsaref/rsaref.c#L275-L278 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | rsaref_finish | static int rsaref_finish(ENGINE *e)
{
return 1;
} | /* Finisher which is only present to make sure this engine looks available */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/rsaref/rsaref.c#L281-L284 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | rsaref_destroy | static int rsaref_destroy(ENGINE *e)
{
ERR_unload_RSAREF_strings();
return 1;
} | /* Destructor (complements the "ENGINE_ncipher()" constructor) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/rsaref/rsaref.c#L287-L291 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | rsaref_mod_exp | static int rsaref_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
{
RSAREFerr(RSAREF_F_RSAREF_MOD_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return(0);
} | /*****************************************************************************
* RSA functions
**/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/rsaref/rsaref.c#L297-L301 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RSAref_bn2bin | static int RSAref_bn2bin(BIGNUM *from, unsigned char *to, int max)
{
int i;
i=BN_num_bytes(from);
if (i > max)
{
RSAREFerr(RSAREF_F_RSAREF_BN2BIN,RSAREF_R_LEN);
return(0);
}
memset(to,0,(unsigned int)max);
if (!BN_bn2bin(from,&(to[max-i])))
return(0);
return(1);
} | /* unsigned char *to: [max] */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/rsaref/rsaref.c#L311-L326 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | rsaref_ciphers | static int rsaref_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
const int **nids, int nid)
{
int ok = 1;
if(!cipher)
{
/* We are returning a list of supported nids */
*nids = rsaref_cipher_nids;
return (sizeof(rsaref_cipher_nids)-1)/sizeof(rsaref_cipher_nids[0]);
}
/* We are being asked for a specific cipher */
switch (nid)
{
case NID_des_cbc:
*cipher = &cipher_des_cbc; break;
case NID_des_ede3_cbc:
*cipher = &cipher_des_ede3_cbc; break;
case NID_desx_cbc:
*cipher = &cipher_desx_cbc; break;
default:
ok = 0;
*cipher = NULL;
break;
}
return ok;
} | /*****************************************************************************
* Symetric cipher and digest function registrars
**/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/rsaref/rsaref.c#L500-L525 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | bind_helper | static int bind_helper ( ENGINE *e )
{
#ifndef OPENSSL_NO_RSA
const RSA_METHOD *meth_rsa ;
#endif
#ifndef OPENSSL_NO_DSA
const DSA_METHOD *meth_dsa ;
#endif
#ifndef OPENSSL_NO_DH
const DH_METHOD *meth_dh ;
#endif
const RAND_METHOD *meth_rand ;
if ( !ENGINE_set_id ( e, engine_zencod_id ) ||
!ENGINE_set_name ( e, engine_zencod_name ) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_RSA ( e, &zencod_rsa ) ||
#endif
#ifndef OPENSSL_NO_DSA
!ENGINE_set_DSA ( e, &zencod_dsa ) ||
#endif
#ifndef OPENSSL_NO_DH
!ENGINE_set_DH ( e, &zencod_dh ) ||
#endif
!ENGINE_set_RAND ( e, &zencod_rand ) ||
!ENGINE_set_destroy_function ( e, zencod_destroy ) ||
!ENGINE_set_init_function ( e, zencod_init ) ||
!ENGINE_set_finish_function ( e, zencod_finish ) ||
!ENGINE_set_ctrl_function ( e, zencod_ctrl ) ||
!ENGINE_set_cmd_defns ( e, zencod_cmd_defns ) ||
!ENGINE_set_digests ( e, engine_digests ) ||
!ENGINE_set_ciphers ( e, engine_ciphers ) ) {
return 0 ;
}
#ifndef OPENSSL_NO_RSA
/* We know that the "PKCS1_SSLeay()" functions hook properly
* to the Zencod-specific mod_exp and mod_exp_crt so we use
* those functions. NB: We don't use ENGINE_openssl() or
* anything "more generic" because something like the RSAref
* code may not hook properly, and if you own one of these
* cards then you have the right to do RSA operations on it
* anyway!
*/
meth_rsa = RSA_PKCS1_SSLeay () ;
zencod_rsa.rsa_pub_enc = meth_rsa->rsa_pub_enc ;
zencod_rsa.rsa_pub_dec = meth_rsa->rsa_pub_dec ;
zencod_rsa.rsa_priv_enc = meth_rsa->rsa_priv_enc ;
zencod_rsa.rsa_priv_dec = meth_rsa->rsa_priv_dec ;
/* meth_rsa->rsa_mod_exp */
/* meth_rsa->bn_mod_exp */
zencod_rsa.init = meth_rsa->init ;
zencod_rsa.finish = meth_rsa->finish ;
#endif
#ifndef OPENSSL_NO_DSA
/* We use OpenSSL meth to supply what we don't provide ;-*)
*/
meth_dsa = DSA_OpenSSL () ;
/* meth_dsa->dsa_do_sign */
zencod_dsa.dsa_sign_setup = meth_dsa->dsa_sign_setup ;
/* meth_dsa->dsa_do_verify */
zencod_dsa.dsa_mod_exp = meth_dsa->dsa_mod_exp ;
/* zencod_dsa.bn_mod_exp = meth_dsa->bn_mod_exp ; */
zencod_dsa.init = meth_dsa->init ;
zencod_dsa.finish = meth_dsa->finish ;
#endif
#ifndef OPENSSL_NO_DH
/* We use OpenSSL meth to supply what we don't provide ;-*)
*/
meth_dh = DH_OpenSSL () ;
/* zencod_dh.generate_key = meth_dh->generate_key ; */
/* zencod_dh.compute_key = meth_dh->compute_key ; */
/* zencod_dh.bn_mod_exp = meth_dh->bn_mod_exp ; */
zencod_dh.init = meth_dh->init ;
zencod_dh.finish = meth_dh->finish ;
#endif
/* We use OpenSSL (SSLeay) meth to supply what we don't provide ;-*)
*/
meth_rand = RAND_SSLeay () ;
/* meth_rand->seed ; */
/* zencod_rand.seed = meth_rand->seed ; */
/* meth_rand->bytes ; */
/* zencod_rand.bytes = meth_rand->bytes ; */
zencod_rand.cleanup = meth_rand->cleanup ;
zencod_rand.add = meth_rand->add ;
/* meth_rand->pseudorand ; */
/* zencod_rand.pseudorand = meth_rand->pseudorand ; */
/* zencod_rand.status = meth_rand->status ; */
/* meth_rand->status ; */
/* Ensure the zencod error handling is set up */
ERR_load_ZENCOD_strings () ;
return 1 ;
} | /* This internal function is used by ENGINE_zencod () and possibly by the
* "dynamic" ENGINE support too ;-)
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L258-L363 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | zencod_destroy | static int zencod_destroy (ENGINE *e )
{
ERR_unload_ZENCOD_strings () ;
return 1 ;
} | /* Destructor (complements the "ENGINE_zencod ()" constructor)
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L465-L471 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | zencod_init | static int zencod_init ( ENGINE *e )
{
t_zencod_test *ptr_0 ;
t_zencod_bytes2bits *ptr_1 ;
t_zencod_bits2bytes *ptr_2 ;
t_zencod_new_number *ptr_3 ;
t_zencod_init_number *ptr_4 ;
t_zencod_rsa_mod_exp *ptr_exp_1 ;
t_zencod_rsa_mod_exp_crt *ptr_exp_2 ;
t_zencod_dsa_do_sign *ptr_dsa_1 ;
t_zencod_dsa_do_verify *ptr_dsa_2 ;
t_zencod_dh_generate_key *ptr_dh_1 ;
t_zencod_dh_compute_key *ptr_dh_2 ;
t_zencod_rand_bytes *ptr_rand_1 ;
t_zencod_math_mod_exp *ptr_math_1 ;
t_zencod_md5_init *ptr_md5_1 ;
t_zencod_md5_update *ptr_md5_2 ;
t_zencod_md5_do_final *ptr_md5_3 ;
t_zencod_sha1_init *ptr_sha1_1 ;
t_zencod_sha1_update *ptr_sha1_2 ;
t_zencod_sha1_do_final *ptr_sha1_3 ;
t_zencod_xdes_cipher *ptr_xdes_1 ;
t_zencod_rc4_cipher *ptr_rc4_1 ;
CHEESE () ;
/*
* We Should add some tests for non NULL parameters or bad value !!
* Stuff to be done ...
*/
if ( zencod_dso != NULL ) {
ZENCODerr ( ZENCOD_F_ZENCOD_INIT, ZENCOD_R_ALREADY_LOADED ) ;
goto err ;
}
/* Trying to load the Library "cryptozen"
*/
zencod_dso = DSO_load ( NULL, ZENCOD_LIBNAME, NULL, 0 ) ;
if ( zencod_dso == NULL ) {
ZENCODerr ( ZENCOD_F_ZENCOD_INIT, ZENCOD_R_DSO_FAILURE ) ;
goto err ;
}
/* Trying to load Function from the Library
*/
if ( ! ( ptr_1 = (t_zencod_bytes2bits*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_1 ) ) ||
! ( ptr_2 = (t_zencod_bits2bytes*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_2 ) ) ||
! ( ptr_3 = (t_zencod_new_number*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_3 ) ) ||
! ( ptr_4 = (t_zencod_init_number*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_4 ) ) ||
! ( ptr_exp_1 = (t_zencod_rsa_mod_exp*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_exp_1 ) ) ||
! ( ptr_exp_2 = (t_zencod_rsa_mod_exp_crt*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_exp_2 ) ) ||
! ( ptr_dsa_1 = (t_zencod_dsa_do_sign*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_dsa_1 ) ) ||
! ( ptr_dsa_2 = (t_zencod_dsa_do_verify*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_dsa_2 ) ) ||
! ( ptr_dh_1 = (t_zencod_dh_generate_key*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_dh_1 ) ) ||
! ( ptr_dh_2 = (t_zencod_dh_compute_key*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_dh_2 ) ) ||
! ( ptr_rand_1 = (t_zencod_rand_bytes*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_rand_1 ) ) ||
! ( ptr_math_1 = (t_zencod_math_mod_exp*) DSO_bind_func ( zencod_dso, ZENCOD_Fct_math_1 ) ) ||
! ( ptr_0 = (t_zencod_test *) DSO_bind_func ( zencod_dso, ZENCOD_Fct_0 ) ) ||
! ( ptr_md5_1 = (t_zencod_md5_init *) DSO_bind_func ( zencod_dso, ZENCOD_Fct_md5_1 ) ) ||
! ( ptr_md5_2 = (t_zencod_md5_update *) DSO_bind_func ( zencod_dso, ZENCOD_Fct_md5_2 ) ) ||
! ( ptr_md5_3 = (t_zencod_md5_do_final *) DSO_bind_func ( zencod_dso, ZENCOD_Fct_md5_3 ) ) ||
! ( ptr_sha1_1 = (t_zencod_sha1_init *) DSO_bind_func ( zencod_dso, ZENCOD_Fct_sha1_1 ) ) ||
! ( ptr_sha1_2 = (t_zencod_sha1_update *) DSO_bind_func ( zencod_dso, ZENCOD_Fct_sha1_2 ) ) ||
! ( ptr_sha1_3 = (t_zencod_sha1_do_final *) DSO_bind_func ( zencod_dso, ZENCOD_Fct_sha1_3 ) ) ||
! ( ptr_xdes_1 = (t_zencod_xdes_cipher *) DSO_bind_func ( zencod_dso, ZENCOD_Fct_xdes_1 ) ) ||
! ( ptr_rc4_1 = (t_zencod_rc4_cipher *) DSO_bind_func ( zencod_dso, ZENCOD_Fct_rc4_1 ) ) ) {
ZENCODerr ( ZENCOD_F_ZENCOD_INIT, ZENCOD_R_DSO_FAILURE ) ;
goto err ;
}
/* The function from "cryptozen" Library have been correctly loaded so copy them
*/
ptr_zencod_test = ptr_0 ;
ptr_zencod_bytes2bits = ptr_1 ;
ptr_zencod_bits2bytes = ptr_2 ;
ptr_zencod_new_number = ptr_3 ;
ptr_zencod_init_number = ptr_4 ;
ptr_zencod_rsa_mod_exp = ptr_exp_1 ;
ptr_zencod_rsa_mod_exp_crt = ptr_exp_2 ;
ptr_zencod_dsa_do_sign = ptr_dsa_1 ;
ptr_zencod_dsa_do_verify = ptr_dsa_2 ;
ptr_zencod_dh_generate_key = ptr_dh_1 ;
ptr_zencod_dh_compute_key = ptr_dh_2 ;
ptr_zencod_rand_bytes = ptr_rand_1 ;
ptr_zencod_math_mod_exp = ptr_math_1 ;
ptr_zencod_test = ptr_0 ;
ptr_zencod_md5_init = ptr_md5_1 ;
ptr_zencod_md5_update = ptr_md5_2 ;
ptr_zencod_md5_do_final = ptr_md5_3 ;
ptr_zencod_sha1_init = ptr_sha1_1 ;
ptr_zencod_sha1_update = ptr_sha1_2 ;
ptr_zencod_sha1_do_final = ptr_sha1_3 ;
ptr_zencod_xdes_cipher = ptr_xdes_1 ;
ptr_zencod_rc4_cipher = ptr_rc4_1 ;
/* We should peform a test to see if there is actually any unit runnig on the system ...
* Even if the cryptozen library is loaded the module coul not be loaded on the system ...
* For now we may just open and close the device !!
*/
if ( ptr_zencod_test () != 0 ) {
ZENCODerr ( ZENCOD_F_ZENCOD_INIT, ZENCOD_R_UNIT_FAILURE ) ;
goto err ;
}
return 1 ;
err :
if ( zencod_dso ) {
DSO_free ( zencod_dso ) ;
}
zencod_dso = NULL ;
ptr_zencod_bytes2bits = NULL ;
ptr_zencod_bits2bytes = NULL ;
ptr_zencod_new_number = NULL ;
ptr_zencod_init_number = NULL ;
ptr_zencod_rsa_mod_exp = NULL ;
ptr_zencod_rsa_mod_exp_crt = NULL ;
ptr_zencod_dsa_do_sign = NULL ;
ptr_zencod_dsa_do_verify = NULL ;
ptr_zencod_dh_generate_key = NULL ;
ptr_zencod_dh_compute_key = NULL ;
ptr_zencod_rand_bytes = NULL ;
ptr_zencod_math_mod_exp = NULL ;
ptr_zencod_test = NULL ;
ptr_zencod_md5_init = NULL ;
ptr_zencod_md5_update = NULL ;
ptr_zencod_md5_do_final = NULL ;
ptr_zencod_sha1_init = NULL ;
ptr_zencod_sha1_update = NULL ;
ptr_zencod_sha1_do_final = NULL ;
ptr_zencod_xdes_cipher = NULL ;
ptr_zencod_rc4_cipher = NULL ;
return 0 ;
} | /* (de)initialisation functions. Control Function
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L476-L612 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | zencod_bn_mod_exp | static int zencod_bn_mod_exp ( BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx )
{
zen_nb_t y, x, e, n;
int ret;
CHEESE () ;
if ( !zencod_dso ) {
ENGINEerr(ZENCOD_F_ZENCOD_BN_MOD_EXP, ZENCOD_R_NOT_LOADED);
return 0;
}
if ( !bn_wexpand(r, m->top + 1) ) {
ENGINEerr(ZENCOD_F_ZENCOD_BN_MOD_EXP, ZENCOD_R_BN_EXPAND_FAIL);
return 0;
}
memset(r->d, 0, BN_num_bytes(m));
ptr_zencod_init_number ( &y, (r->dmax - 1) * sizeof (BN_ULONG) * 8, (unsigned char *) r->d ) ;
BIGNUM2ZEN ( &x, a ) ;
BIGNUM2ZEN ( &e, p ) ;
BIGNUM2ZEN ( &n, m ) ;
/* Must invert x and e parameter due to BN mod exp prototype ... */
ret = ptr_zencod_math_mod_exp ( &y, &e, &x, &n ) ;
if ( ret ) {
PERROR("zenbridge_math_mod_exp");
ENGINEerr(ZENCOD_F_ZENCOD_BN_MOD_EXP, ZENCOD_R_REQUEST_FAILED);
return 0;
}
r->top = (BN_num_bits(m) + BN_BITS2 - 1) / BN_BITS2;
return 1;
} | /* BIGNUM stuff Functions
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L696-L732 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RSA_zencod_bn_mod_exp | static int RSA_zencod_bn_mod_exp ( BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx )
{
CHEESE () ;
if ( !zencod_dso ) {
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP, ZENCOD_R_NOT_LOADED);
return 0;
}
/* Do in software if argument is too large for hardware */
if ( BN_num_bits(m) > ZENBRIDGE_MAX_KEYSIZE_RSA ) {
const RSA_METHOD *meth;
meth = RSA_PKCS1_SSLeay();
return meth->bn_mod_exp(r, a, p, m, ctx, m_ctx);
} else {
zen_nb_t y, x, e, n;
if ( !bn_expand(r, BN_num_bits(m)) ) {
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP, ZENCOD_R_BN_EXPAND_FAIL);
return 0;
}
r->top = (BN_num_bits(m) + BN_BITS2 - 1) / BN_BITS2;
BIGNUM2ZEN ( &x, a ) ;
BIGNUM2ZEN ( &y, r ) ;
BIGNUM2ZEN ( &e, p ) ;
BIGNUM2ZEN ( &n, m ) ;
if ( ptr_zencod_rsa_mod_exp ( &y, &x, &n, &e ) < 0 ) {
PERROR("zenbridge_rsa_mod_exp");
ENGINEerr(ZENCOD_F_ZENCOD_RSA_MOD_EXP, ZENCOD_R_REQUEST_FAILED);
return 0;
}
return 1;
}
} | /* This function is aliased to RSA_mod_exp (with the mont stuff dropped).
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L789-L828 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | DH_zencod_generate_key | static int DH_zencod_generate_key ( DH *dh )
{
BIGNUM *bn_prv = NULL;
BIGNUM *bn_pub = NULL;
zen_nb_t y, x, g, p;
int generate_x;
CHEESE();
if ( !zencod_dso ) {
ENGINEerr(ZENCOD_F_ZENCOD_DH_GENERATE, ZENCOD_R_NOT_LOADED);
return 0;
}
/* Private key */
if ( dh->priv_key ) {
bn_prv = dh->priv_key;
generate_x = 0;
} else {
if (!(bn_prv = BN_new())) {
ENGINEerr(ZENCOD_F_ZENCOD_DH_GENERATE, ZENCOD_R_BN_EXPAND_FAIL);
goto FAILED;
}
generate_x = 1;
}
/* Public key */
if ( dh->pub_key )
bn_pub = dh->pub_key;
else
if ( !( bn_pub = BN_new () ) ) {
ENGINEerr(ZENCOD_F_ZENCOD_DH_GENERATE, ZENCOD_R_BN_EXPAND_FAIL);
goto FAILED;
}
/* Expand */
if ( !bn_wexpand ( bn_prv, dh->p->dmax ) ||
!bn_wexpand ( bn_pub, dh->p->dmax ) ) {
ENGINEerr(ZENCOD_F_ZENCOD_DH_GENERATE, ZENCOD_R_BN_EXPAND_FAIL);
goto FAILED;
}
bn_prv->top = dh->p->top;
bn_pub->top = dh->p->top;
/* Convert all keys */
BIGNUM2ZEN ( &p, dh->p ) ;
BIGNUM2ZEN ( &g, dh->g ) ;
BIGNUM2ZEN ( &y, bn_pub ) ;
BIGNUM2ZEN ( &x, bn_prv ) ;
x.len = DH_size(dh) * 8;
/* Adjust the lengths of P and G */
p.len = ptr_zencod_bytes2bits ( p.data, ZEN_BYTES ( p.len ) ) ;
g.len = ptr_zencod_bytes2bits ( g.data, ZEN_BYTES ( g.len ) ) ;
/* Send the request to the driver */
if ( ptr_zencod_dh_generate_key ( &y, &x, &g, &p, generate_x ) < 0 ) {
perror("zenbridge_dh_generate_key");
ENGINEerr(ZENCOD_F_ZENCOD_DH_GENERATE, ZENCOD_R_REQUEST_FAILED);
goto FAILED;
}
dh->priv_key = bn_prv;
dh->pub_key = bn_pub;
return 1;
FAILED:
if (!dh->priv_key && bn_prv)
BN_free(bn_prv);
if (!dh->pub_key && bn_pub)
BN_free(bn_pub);
return 0;
} | /* DH stuff Functions
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L971-L1045 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RAND_zencod_seed | static void RAND_zencod_seed ( const void *buf, int num )
{
/* Nothing to do cause our crypto accelerator provide a true random generator */
} | /* !OPENSSL_NO_DH */
/* RAND stuff Functions
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L1101-L1104 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | engine_digests | static int engine_digests ( ENGINE *e, const EVP_MD **digest, const int **nids, int nid )
{
#ifdef DEBUG_ZENCOD_MD
fprintf ( stderr, "\t=>Function : static int engine_digests () called !\n" ) ;
#endif
if ( !digest ) {
/* We are returning a list of supported nids */
*nids = engine_digest_nids ;
return engine_digest_nids_num ;
}
/* We are being asked for a specific digest */
if ( nid == NID_md5 ) {
*digest = &engine_md5_md ;
}
else if ( nid == NID_sha1 ) {
*digest = &engine_sha1_md ;
}
else {
*digest = NULL ;
return 0 ;
}
return 1 ;
} | /* General function cloned on hw_openbsd_dev_crypto one ... */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L1359-L1383 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | engine_sha1_init | static int engine_sha1_init ( EVP_MD_CTX *ctx )
{
int to_return = 0 ;
/* Test with zenbridge library ... */
to_return = ptr_zencod_sha1_init ( (ZEN_MD_DATA *) ctx->md_data ) ;
to_return = !to_return ;
return to_return ;
} | /* SHA stuff Functions
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L1388-L1398 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | engine_md5_init | static int engine_md5_init ( EVP_MD_CTX *ctx )
{
int to_return = 0 ;
/* Test with zenbridge library ... */
to_return = ptr_zencod_md5_init ( (ZEN_MD_DATA *) ctx->md_data ) ;
to_return = !to_return ;
return to_return ;
} | /* MD5 stuff Functions
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L1440-L1450 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | engine_ciphers | static int engine_ciphers ( ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid )
{
if ( !cipher ) {
/* We are returning a list of supported nids */
*nids = engine_cipher_nids ;
return engine_cipher_nids_num ;
}
/* We are being asked for a specific cipher */
if ( nid == NID_rc4 ) {
*cipher = &engine_rc4 ;
}
else if ( nid == NID_rc4_40 ) {
*cipher = &engine_rc4_40 ;
}
else if ( nid == NID_des_cbc ) {
*cipher = &engine_des_cbc ;
}
else if ( nid == NID_des_ede3_cbc ) {
*cipher = &engine_des_ede3_cbc ;
}
else {
*cipher = NULL ;
return 0 ;
}
return 1 ;
} | /* General function cloned on hw_openbsd_dev_crypto one ... */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/engines/zencod/hw_zencod.c#L1517-L1544 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | main | int main(int argc, char **argv)
{
FILE *fp;
EVP_PKEY *pkey;
X509 *cert;
STACK_OF(X509) *ca = NULL;
PKCS12 *p12;
int i;
if (argc != 4) {
fprintf(stderr, "Usage: pkread p12file password opfile\n");
exit (1);
}
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
if (!(fp = fopen(argv[1], "rb"))) {
fprintf(stderr, "Error opening file %s\n", argv[1]);
exit(1);
}
p12 = d2i_PKCS12_fp(fp, NULL);
fclose (fp);
if (!p12) {
fprintf(stderr, "Error reading PKCS#12 file\n");
ERR_print_errors_fp(stderr);
exit (1);
}
if (!PKCS12_parse(p12, argv[2], &pkey, &cert, &ca)) {
fprintf(stderr, "Error parsing PKCS#12 file\n");
ERR_print_errors_fp(stderr);
exit (1);
}
PKCS12_free(p12);
if (!(fp = fopen(argv[3], "w"))) {
fprintf(stderr, "Error opening file %s\n", argv[1]);
exit(1);
}
if (pkey) {
fprintf(fp, "***Private Key***\n");
PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL);
}
if (cert) {
fprintf(fp, "***User Certificate***\n");
PEM_write_X509_AUX(fp, cert);
}
if (ca && sk_X509_num(ca)) {
fprintf(fp, "***Other Certificates***\n");
for (i = 0; i < sk_X509_num(ca); i++)
PEM_write_X509_AUX(fp, sk_X509_value(ca, i));
}
fclose(fp);
return 0;
} | /* Simple PKCS#12 file reader */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/pkcs12/pkread.c#L11-L61 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | main | int main(int argc, char **argv)
{
FILE *fp;
EVP_PKEY *pkey;
X509 *cert;
PKCS12 *p12;
if (argc != 5) {
fprintf(stderr, "Usage: pkwrite infile password name p12file\n");
exit(1);
}
SSLeay_add_all_algorithms();
ERR_load_crypto_strings();
if (!(fp = fopen(argv[1], "r"))) {
fprintf(stderr, "Error opening file %s\n", argv[1]);
exit(1);
}
cert = PEM_read_X509(fp, NULL, NULL, NULL);
rewind(fp);
pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);
fclose(fp);
p12 = PKCS12_create(argv[2], argv[3], pkey, cert, NULL, 0,0,0,0,0);
if(!p12) {
fprintf(stderr, "Error creating PKCS#12 structure\n");
ERR_print_errors_fp(stderr);
exit(1);
}
if (!(fp = fopen(argv[4], "wb"))) {
fprintf(stderr, "Error opening file %s\n", argv[1]);
ERR_print_errors_fp(stderr);
exit(1);
}
i2d_PKCS12_fp(fp, p12);
PKCS12_free(p12);
fclose(fp);
return 0;
} | /* Simple PKCS#12 file creator */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/pkcs12/pkwrite.c#L11-L46 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | buffer_used | unsigned int buffer_used(buffer_t *buf) {
return buf->used; } | /* Code these simple ones in compact form */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/buffer.c#L18-L19 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | buffer_adddata | static unsigned int buffer_adddata(buffer_t *buf, const unsigned char *ptr,
unsigned int size)
{
unsigned int added = MAX_DATA_SIZE - buf->used;
if(added > size)
added = size;
if(added == 0)
return 0;
memcpy(buf->data + buf->used, ptr, added);
buf->used += added;
buf->total_in += added;
return added;
} | /* To avoid "unused" warnings */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/buffer.c#L40-L52 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | cb_ssl_info | void cb_ssl_info(const SSL *s, int where, int ret)
{
const char *str1, *str2;
int w;
if(!fp_cb_ssl_info)
return;
w = where & ~SSL_ST_MASK;
str1 = (w & SSL_ST_CONNECT ? "SSL_connect" : (w & SSL_ST_ACCEPT ?
"SSL_accept" : "undefined")),
str2 = SSL_state_string_long(s);
if (where & SSL_CB_LOOP)
fprintf(fp_cb_ssl_info, "(%s) %s\n", str1, str2);
else if (where & SSL_CB_EXIT) {
if (ret == 0)
fprintf(fp_cb_ssl_info, "(%s) failed in %s\n", str1, str2);
/* In a non-blocking model, we get a few of these "error"s simply because we're
* calling "reads" and "writes" on the state-machine that are virtual NOPs
* simply to avoid wasting the time seeing if we *should* call them. Removing
* this case makes the "-out_state" output a lot easier on the eye. */
#if 0
else if (ret < 0)
fprintf(fp_cb_ssl_info, "%s:error in %s\n", str1, str2);
#endif
}
} | /* This function is largely borrowed from the one used in OpenSSL's "s_client"
* and "s_server" utilities. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/cb.c#L20-L47 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | cb_ssl_verify | int cb_ssl_verify(int ok, X509_STORE_CTX *ctx)
{
char buf1[256]; /* Used for the subject name */
char buf2[256]; /* Used for the issuer name */
const char *reason = NULL; /* Error reason (if any) */
X509 *err_cert;
int err, depth;
if(!fp_cb_ssl_verify || (cb_ssl_verify_level == 0))
return ok;
err_cert = X509_STORE_CTX_get_current_cert(ctx);
err = X509_STORE_CTX_get_error(ctx);
depth = X509_STORE_CTX_get_error_depth(ctx);
buf1[0] = buf2[0] = '\0';
/* Fill buf1 */
X509_NAME_oneline(X509_get_subject_name(err_cert), buf1, 256);
/* Fill buf2 */
X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert), buf2, 256);
switch (ctx->error) {
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
reason = int_reason_no_issuer;
break;
case X509_V_ERR_CERT_NOT_YET_VALID:
reason = int_reason_not_yet;
break;
case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
reason = int_reason_before;
break;
case X509_V_ERR_CERT_HAS_EXPIRED:
reason = int_reason_expired;
break;
case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
reason = int_reason_after;
break;
}
if((cb_ssl_verify_level == 1) && ok)
return ok;
fprintf(fp_cb_ssl_verify, "chain-depth=%d, ", depth);
if(reason)
fprintf(fp_cb_ssl_verify, "error=%s\n", reason);
else
fprintf(fp_cb_ssl_verify, "error=%d\n", err);
if(cb_ssl_verify_level < 3)
return ok;
fprintf(fp_cb_ssl_verify, "--> subject = %s\n", buf1);
fprintf(fp_cb_ssl_verify, "--> issuer = %s\n", buf2);
if(!ok)
fprintf(fp_cb_ssl_verify,"--> verify error:num=%d:%s\n",err,
X509_verify_cert_error_string(err));
fprintf(fp_cb_ssl_verify, "--> verify return:%d\n",ok);
return ok;
} | /* Stolen wholesale from apps/s_cb.c :-) And since then, mutilated ... */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/cb.c#L61-L114 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ip_initialise | int ip_initialise(void)
{
struct sigaction sa;
sa.sa_handler = SIG_IGN;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
if(sigaction(SIGPIPE, &sa, NULL) != 0)
return 0;
return 1;
} | /* Any IP-related initialisations. For now, this means blocking SIGPIPE */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/ip.c#L9-L19 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | state_machine_churn | int state_machine_churn(state_machine_t *machine)
{
unsigned int loop;
if(machine->ssl == NULL) {
if(buffer_empty(&machine->clean_out))
/* Time to close this state-machine altogether */
return 0;
else
/* Still buffered data on the clean side to go out */
return 1;
}
/* Do this loop twice to cover any dependencies about which precise
* order of reads and writes is required. */
for(loop = 0; loop < 2; loop++) {
buffer_to_SSL(&machine->clean_in, machine->ssl);
buffer_to_BIO(&machine->dirty_in, machine->bio_intossl);
buffer_from_SSL(&machine->clean_out, machine->ssl);
buffer_from_BIO(&machine->dirty_out, machine->bio_fromssl);
}
/* We close on the SSL side if the info callback noticed some problems
* or an SSL shutdown was underway and shutdown traffic had all been
* sent. */
if(SSL_get_app_data(machine->ssl) || (SSL_get_shutdown(machine->ssl) &&
buffer_empty(&machine->dirty_out))) {
/* Great, we can seal off the dirty side completely */
if(!state_machine_close_dirty(machine))
return 0;
}
/* Either the SSL is alive and well, or the closing process still has
* outgoing data waiting to be sent */
return 1;
} | /* Performs the data-IO loop and returns zero if the machine should close */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/sm.c#L82-L113 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | state_machine_close_clean | int state_machine_close_clean(state_machine_t *machine)
{
/* Well, first thing to do is null out the clean-side buffers - they're
* no use any more. */
buffer_close(&machine->clean_in);
buffer_close(&machine->clean_out);
/* And start an SSL shutdown */
if(machine->ssl)
SSL_shutdown(machine->ssl);
/* This is an "event", so flush the SSL of any generated traffic */
state_machine_churn(machine);
if(buffer_empty(&machine->dirty_in) &&
buffer_empty(&machine->dirty_out))
return 0;
return 1;
} | /* Called when the clean side of the SSL has lost its connection */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/sm.c#L116-L131 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | state_machine_close_dirty | int state_machine_close_dirty(state_machine_t *machine)
{
buffer_close(&machine->dirty_in);
buffer_close(&machine->dirty_out);
buffer_close(&machine->clean_in);
if(machine->ssl)
SSL_free(machine->ssl);
machine->ssl = NULL;
machine->bio_intossl = machine->bio_fromssl = NULL;
if(buffer_empty(&machine->clean_out))
return 0;
return 1;
} | /* Called when the dirty side of the SSL has lost its connection. This is pretty
* terminal as all that can be left to do is send any buffered output on the
* clean side - after that, we're done. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/sm.c#L136-L148 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | usage | static int usage(const char *errstr, int isunknownarg)
{
if(isunknownarg)
fprintf(stderr, "Error: unknown argument '%s'\n", errstr);
else
fprintf(stderr, "Error: %s\n", errstr);
fprintf(stderr, "%s\n", helpstring);
return 1;
} | /* Various help/error messages used by main() */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/tunala.c#L200-L208 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ctx_set_cert | static int ctx_set_cert(SSL_CTX *ctx, const char *cert, const char *key)
{
FILE *fp = NULL;
X509 *x509 = NULL;
EVP_PKEY *pkey = NULL;
int toret = 0; /* Assume an error */
/* cert */
if(cert) {
if((fp = fopen(cert, "r")) == NULL) {
fprintf(stderr, "Error opening cert file '%s'\n", cert);
goto err;
}
if(!PEM_read_X509(fp, &x509, NULL, NULL)) {
fprintf(stderr, "Error reading PEM cert from '%s'\n",
cert);
goto err;
}
if(!SSL_CTX_use_certificate(ctx, x509)) {
fprintf(stderr, "Error, cert in '%s' can not be used\n",
cert);
goto err;
}
/* Clear the FILE* for reuse in the "key" code */
fclose(fp);
fp = NULL;
fprintf(stderr, "Info, operating with cert in '%s'\n", cert);
/* If a cert was given without matching key, we assume the same
* file contains the required key. */
if(!key)
key = cert;
} else {
if(key)
fprintf(stderr, "Error, can't specify a key without a "
"corresponding certificate\n");
else
fprintf(stderr, "Error, ctx_set_cert called with "
"NULLs!\n");
goto err;
}
/* key */
if(key) {
if((fp = fopen(key, "r")) == NULL) {
fprintf(stderr, "Error opening key file '%s'\n", key);
goto err;
}
if(!PEM_read_PrivateKey(fp, &pkey, NULL, NULL)) {
fprintf(stderr, "Error reading PEM key from '%s'\n",
key);
goto err;
}
if(!SSL_CTX_use_PrivateKey(ctx, pkey)) {
fprintf(stderr, "Error, key in '%s' can not be used\n",
key);
goto err;
}
fprintf(stderr, "Info, operating with key in '%s'\n", key);
} else
fprintf(stderr, "Info, operating without a cert or key\n");
/* Success */
toret = 1; err:
if(x509)
X509_free(x509);
if(pkey)
EVP_PKEY_free(pkey);
if(fp)
fclose(fp);
return toret;
} | /****************/
/* OpenSSL bits */
/****************/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/tunala.c#L607-L675 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | selector_sets_init | static void selector_sets_init(select_sets_t *s)
{
s->max = 0;
FD_ZERO(&s->reads);
FD_ZERO(&s->sends);
FD_ZERO(&s->excepts);
} | /*****************/
/* Selector bits */
/*****************/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/tunala.c#L838-L844 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | selector_get_listener | static int selector_get_listener(tunala_selector_t *selector, int fd, int *newfd)
{
if(FD_ISSET(fd, &selector->last_selected.excepts))
return -1;
if(!FD_ISSET(fd, &selector->last_selected.reads))
return 0;
if((*newfd = ip_accept_connection(fd)) == -1)
return -1;
return 1;
} | /* This returns -1 for error, 0 for no new connections, or 1 for success, in
* which case *newfd is populated. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/tunala.c#L912-L921 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | tunala_world_make_room | static int tunala_world_make_room(tunala_world_t *world)
{
unsigned int newsize;
tunala_item_t *newarray;
if(world->tunnels_used < world->tunnels_size)
return 1;
newsize = (world->tunnels_size == 0 ? 16 :
((world->tunnels_size * 3) / 2));
if((newarray = malloc(newsize * sizeof(tunala_item_t))) == NULL)
return 0;
memset(newarray, 0, newsize * sizeof(tunala_item_t));
if(world->tunnels_used > 0)
memcpy(newarray, world->tunnels,
world->tunnels_used * sizeof(tunala_item_t));
if(world->tunnels_size > 0)
free(world->tunnels);
/* migrate */
world->tunnels = newarray;
world->tunnels_size = newsize;
return 1;
} | /************************/
/* "Tunala" world stuff */
/************************/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/tunala/tunala.c#L927-L948 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | add_ext | int add_ext(X509 *cert, int nid, char *value)
{
X509_EXTENSION *ex;
X509V3_CTX ctx;
/* This sets the 'context' of the extensions. */
/* No configuration database */
X509V3_set_ctx_nodb(&ctx);
/* Issuer and subject certs: both the target since it is self signed,
* no request and no CRL
*/
X509V3_set_ctx(&ctx, cert, cert, NULL, NULL, 0);
ex = X509V3_EXT_conf_nid(NULL, &ctx, nid, value);
if (!ex)
return 0;
X509_add_ext(cert,ex,-1);
X509_EXTENSION_free(ex);
return 1;
} | /* Add extension using V3 code: we can set the config file as NULL
* because we wont reference any other sections.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/x509/mkcert.c#L153-L171 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | add_ext | int add_ext(STACK_OF(X509_REQUEST) *sk, int nid, char *value)
{
X509_EXTENSION *ex;
ex = X509V3_EXT_conf_nid(NULL, NULL, nid, value);
if (!ex)
return 0;
sk_X509_EXTENSION_push(sk, ex);
return 1;
} | /* Add extension using V3 code: we can set the config file as NULL
* because we wont reference any other sections.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/demos/x509/mkreq.c#L151-L160 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | bind_helper | static int bind_helper(ENGINE *e)
{
if(!ENGINE_set_id(e, engine_4758_cca_id) ||
!ENGINE_set_name(e, engine_4758_cca_name) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_RSA(e, &ibm_4758_cca_rsa) ||
#endif
!ENGINE_set_RAND(e, &ibm_4758_cca_rand) ||
!ENGINE_set_destroy_function(e, ibm_4758_cca_destroy) ||
!ENGINE_set_init_function(e, ibm_4758_cca_init) ||
!ENGINE_set_finish_function(e, ibm_4758_cca_finish) ||
!ENGINE_set_ctrl_function(e, ibm_4758_cca_ctrl) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_load_privkey_function(e, ibm_4758_load_privkey) ||
!ENGINE_set_load_pubkey_function(e, ibm_4758_load_pubkey) ||
#endif
!ENGINE_set_cmd_defns(e, cca4758_cmd_defns))
return 0;
/* Ensure the error handling is set up */
ERR_load_CCA4758_strings();
return 1;
} | /* engine implementation */
/*-----------------------*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_4758cca.c#L218-L239 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | cca_random_status | static int cca_random_status(void)
{
return 1;
} | /* OPENSSL_NO_RSA */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_4758cca.c#L925-L928 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | bind_aep | static int bind_aep(ENGINE *e)
{
#ifndef OPENSSL_NO_RSA
const RSA_METHOD *meth1;
#endif
#ifndef OPENSSL_NO_DSA
const DSA_METHOD *meth2;
#endif
#ifndef OPENSSL_NO_DH
const DH_METHOD *meth3;
#endif
if(!ENGINE_set_id(e, engine_aep_id) ||
!ENGINE_set_name(e, engine_aep_name) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_RSA(e, &aep_rsa) ||
#endif
#ifndef OPENSSL_NO_DSA
!ENGINE_set_DSA(e, &aep_dsa) ||
#endif
#ifndef OPENSSL_NO_DH
!ENGINE_set_DH(e, &aep_dh) ||
#endif
#ifdef AEPRAND
!ENGINE_set_RAND(e, &aep_random) ||
#endif
!ENGINE_set_init_function(e, aep_init) ||
!ENGINE_set_destroy_function(e, aep_destroy) ||
!ENGINE_set_finish_function(e, aep_finish) ||
!ENGINE_set_ctrl_function(e, aep_ctrl) ||
!ENGINE_set_cmd_defns(e, aep_cmd_defns))
return 0;
#ifndef OPENSSL_NO_RSA
/* We know that the "PKCS1_SSLeay()" functions hook properly
* to the aep-specific mod_exp and mod_exp_crt so we use
* those functions. NB: We don't use ENGINE_openssl() or
* anything "more generic" because something like the RSAref
* code may not hook properly, and if you own one of these
* cards then you have the right to do RSA operations on it
* anyway! */
meth1 = RSA_PKCS1_SSLeay();
aep_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
aep_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
aep_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
aep_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
#endif
#ifndef OPENSSL_NO_DSA
/* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
* bits. */
meth2 = DSA_OpenSSL();
aep_dsa.dsa_do_sign = meth2->dsa_do_sign;
aep_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
aep_dsa.dsa_do_verify = meth2->dsa_do_verify;
aep_dsa = *DSA_get_default_method();
aep_dsa.dsa_mod_exp = aep_dsa_mod_exp;
aep_dsa.bn_mod_exp = aep_mod_exp_dsa;
#endif
#ifndef OPENSSL_NO_DH
/* Much the same for Diffie-Hellman */
meth3 = DH_OpenSSL();
aep_dh.generate_key = meth3->generate_key;
aep_dh.compute_key = meth3->compute_key;
aep_dh.bn_mod_exp = meth3->bn_mod_exp;
#endif
/* Ensure the aep error handling is set up */
ERR_load_AEPHK_strings();
return 1;
} | /* This internal function is used by ENGINE_aep() and possibly by the
* "dynamic" ENGINE support too */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_aep.c#L267-L341 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | aep_init | static int aep_init(ENGINE *e)
{
t_AEP_ModExp *p1;
t_AEP_ModExpCrt *p2;
#ifdef AEPRAND
t_AEP_GenRandom *p3;
#endif
t_AEP_Finalize *p4;
t_AEP_Initialize *p5;
t_AEP_OpenConnection *p6;
t_AEP_SetBNCallBacks *p7;
t_AEP_CloseConnection *p8;
int to_return = 0;
if(aep_dso != NULL)
{
AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_ALREADY_LOADED);
goto err;
}
/* Attempt to load libaep.so. */
aep_dso = DSO_load(NULL, get_AEP_LIBNAME(), NULL, 0);
if(aep_dso == NULL)
{
AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED);
goto err;
}
if( !(p1 = (t_AEP_ModExp *) DSO_bind_func( aep_dso,AEP_F1)) ||
!(p2 = (t_AEP_ModExpCrt*) DSO_bind_func( aep_dso,AEP_F2)) ||
#ifdef AEPRAND
!(p3 = (t_AEP_GenRandom*) DSO_bind_func( aep_dso,AEP_F3)) ||
#endif
!(p4 = (t_AEP_Finalize*) DSO_bind_func( aep_dso,AEP_F4)) ||
!(p5 = (t_AEP_Initialize*) DSO_bind_func( aep_dso,AEP_F5)) ||
!(p6 = (t_AEP_OpenConnection*) DSO_bind_func( aep_dso,AEP_F6)) ||
!(p7 = (t_AEP_SetBNCallBacks*) DSO_bind_func( aep_dso,AEP_F7)) ||
!(p8 = (t_AEP_CloseConnection*) DSO_bind_func( aep_dso,AEP_F8)))
{
AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED);
goto err;
}
/* Copy the pointers */
p_AEP_ModExp = p1;
p_AEP_ModExpCrt = p2;
#ifdef AEPRAND
p_AEP_GenRandom = p3;
#endif
p_AEP_Finalize = p4;
p_AEP_Initialize = p5;
p_AEP_OpenConnection = p6;
p_AEP_SetBNCallBacks = p7;
p_AEP_CloseConnection = p8;
to_return = 1;
return to_return;
err:
if(aep_dso)
DSO_free(aep_dso);
aep_dso = NULL;
p_AEP_OpenConnection = NULL;
p_AEP_ModExp = NULL;
p_AEP_ModExpCrt = NULL;
#ifdef AEPRAND
p_AEP_GenRandom = NULL;
#endif
p_AEP_Initialize = NULL;
p_AEP_Finalize = NULL;
p_AEP_SetBNCallBacks = NULL;
p_AEP_CloseConnection = NULL;
return to_return;
} | /* (de)initialisation functions. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_aep.c#L433-L513 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | aep_destroy | static int aep_destroy(ENGINE *e)
{
free_AEP_LIBNAME();
ERR_unload_AEPHK_strings();
return 1;
} | /* Destructor (complements the "ENGINE_aep()" constructor) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_aep.c#L516-L521 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | aep_mod_exp_mont | static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
{
return aep_mod_exp(r, a, p, m, ctx);
} | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_aep.c#L845-L849 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | aep_mod_exp_dh | static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
BN_MONT_CTX *m_ctx)
{
return aep_mod_exp(r, a, p, m, ctx);
} | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_aep.c#L854-L859 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | GetBigNumSize | static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize)
{
BIGNUM* bn;
/*Cast the ArbBigNum pointer to our BIGNUM struct*/
bn = (BIGNUM*) ArbBigNum;
#ifdef SIXTY_FOUR_BIT_LONG
*BigNumSize = bn->top << 3;
#else
/*Size of the bignum in bytes is equal to the bn->top (no of 32 bit
words) multiplies by 4*/
*BigNumSize = bn->top << 2;
#endif
return AEP_R_OK;
} | /*BigNum call back functions, used to convert OpenSSL bignums into AEP bignums.
Note only 32bit Openssl build support*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_aep.c#L1049-L1065 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ConvertAEPBigNum | static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize,
unsigned char* AEP_BigNum)
{
BIGNUM* bn;
#ifndef SIXTY_FOUR_BIT_LONG
int i;
#endif
bn = (BIGNUM*)ArbBigNum;
/*Expand the result bn so that it can hold our big num.
Size is in bits*/
bn_expand(bn, (int)(BigNumSize << 3));
#ifdef SIXTY_FOUR_BIT_LONG
bn->top = BigNumSize >> 3;
if((BigNumSize & 7) != 0)
bn->top++;
memset(bn->d, 0, bn->top << 3);
memcpy(bn->d, AEP_BigNum, BigNumSize);
#else
bn->top = BigNumSize >> 2;
for(i=0;i<bn->top;i++)
{
bn->d[i] = (AEP_U32)
((unsigned) AEP_BigNum[3] << 8 | AEP_BigNum[2]) << 16 |
((unsigned) AEP_BigNum[1] << 8 | AEP_BigNum[0]);
AEP_BigNum += 4;
}
#endif
return AEP_R_OK;
} | /*Turn an AEP Big Num back to a user big num*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_aep.c#L1101-L1137 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | bind_helper | static int bind_helper(ENGINE *e)
{
#ifndef OPENSSL_NO_RSA
const RSA_METHOD *meth1;
#endif
#ifndef OPENSSL_NO_DSA
const DSA_METHOD *meth2;
#endif
#ifndef OPENSSL_NO_DH
const DH_METHOD *meth3;
#endif
if(!ENGINE_set_id(e, engine_atalla_id) ||
!ENGINE_set_name(e, engine_atalla_name) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_RSA(e, &atalla_rsa) ||
#endif
#ifndef OPENSSL_NO_DSA
!ENGINE_set_DSA(e, &atalla_dsa) ||
#endif
#ifndef OPENSSL_NO_DH
!ENGINE_set_DH(e, &atalla_dh) ||
#endif
!ENGINE_set_destroy_function(e, atalla_destroy) ||
!ENGINE_set_init_function(e, atalla_init) ||
!ENGINE_set_finish_function(e, atalla_finish) ||
!ENGINE_set_ctrl_function(e, atalla_ctrl) ||
!ENGINE_set_cmd_defns(e, atalla_cmd_defns))
return 0;
#ifndef OPENSSL_NO_RSA
/* We know that the "PKCS1_SSLeay()" functions hook properly
* to the atalla-specific mod_exp and mod_exp_crt so we use
* those functions. NB: We don't use ENGINE_openssl() or
* anything "more generic" because something like the RSAref
* code may not hook properly, and if you own one of these
* cards then you have the right to do RSA operations on it
* anyway! */
meth1 = RSA_PKCS1_SSLeay();
atalla_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
atalla_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
atalla_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
atalla_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
#endif
#ifndef OPENSSL_NO_DSA
/* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
* bits. */
meth2 = DSA_OpenSSL();
atalla_dsa.dsa_do_sign = meth2->dsa_do_sign;
atalla_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
atalla_dsa.dsa_do_verify = meth2->dsa_do_verify;
#endif
#ifndef OPENSSL_NO_DH
/* Much the same for Diffie-Hellman */
meth3 = DH_OpenSSL();
atalla_dh.generate_key = meth3->generate_key;
atalla_dh.compute_key = meth3->compute_key;
#endif
/* Ensure the atalla error handling is set up */
ERR_load_ATALLA_strings();
return 1;
} | /* This internal function is used by ENGINE_atalla() and possibly by the
* "dynamic" ENGINE support too */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_atalla.c#L195-L258 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | atalla_destroy | static int atalla_destroy(ENGINE *e)
{
free_ATALLA_LIBNAME();
/* Unload the atalla error strings so any error state including our
* functs or reasons won't lead to a segfault (they simply get displayed
* without corresponding string data because none will be found). */
ERR_unload_ATALLA_strings();
return 1;
} | /* Destructor (complements the "ENGINE_atalla()" constructor) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_atalla.c#L329-L337 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | atalla_init | static int atalla_init(ENGINE *e)
{
tfnASI_GetHardwareConfig *p1;
tfnASI_RSAPrivateKeyOpFn *p2;
tfnASI_GetPerformanceStatistics *p3;
/* Not sure of the origin of this magic value, but Ben's code had it
* and it seemed to have been working for a few people. :-) */
unsigned int config_buf[1024];
if(atalla_dso != NULL)
{
ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_ALREADY_LOADED);
goto err;
}
/* Attempt to load libatasi.so/atasi.dll/whatever. Needs to be
* changed unfortunately because the Atalla drivers don't have
* standard library names that can be platform-translated well. */
/* TODO: Work out how to actually map to the names the Atalla
* drivers really use - for now a symbollic link needs to be
* created on the host system from libatasi.so to atasi.so on
* unix variants. */
atalla_dso = DSO_load(NULL, get_ATALLA_LIBNAME(), NULL, 0);
if(atalla_dso == NULL)
{
ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED);
goto err;
}
if(!(p1 = (tfnASI_GetHardwareConfig *)DSO_bind_func(
atalla_dso, ATALLA_F1)) ||
!(p2 = (tfnASI_RSAPrivateKeyOpFn *)DSO_bind_func(
atalla_dso, ATALLA_F2)) ||
!(p3 = (tfnASI_GetPerformanceStatistics *)DSO_bind_func(
atalla_dso, ATALLA_F3)))
{
ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED);
goto err;
}
/* Copy the pointers */
p_Atalla_GetHardwareConfig = p1;
p_Atalla_RSAPrivateKeyOpFn = p2;
p_Atalla_GetPerformanceStatistics = p3;
/* Perform a basic test to see if there's actually any unit
* running. */
if(p1(0L, config_buf) != 0)
{
ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_UNIT_FAILURE);
goto err;
}
/* Everything's fine. */
return 1;
err:
if(atalla_dso)
DSO_free(atalla_dso);
atalla_dso = NULL;
p_Atalla_GetHardwareConfig = NULL;
p_Atalla_RSAPrivateKeyOpFn = NULL;
p_Atalla_GetPerformanceStatistics = NULL;
return 0;
} | /* (de)initialisation functions. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_atalla.c#L340-L398 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | atalla_dsa_mod_exp | static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
BN_CTX *ctx, BN_MONT_CTX *in_mont)
{
BIGNUM t;
int to_return = 0;
BN_init(&t);
/* let rr = a1 ^ p1 mod m */
if (!atalla_mod_exp(rr,a1,p1,m,ctx)) goto end;
/* let t = a2 ^ p2 mod m */
if (!atalla_mod_exp(&t,a2,p2,m,ctx)) goto end;
/* let rr = rr * t mod m */
if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
to_return = 1;
end:
BN_free(&t);
return to_return;
} | /* This code was liberated and adapted from the commented-out code in
* dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
* (it doesn't have a CRT form for RSA), this function means that an
* Atalla system running with a DSA server certificate can handshake
* around 5 or 6 times faster/more than an equivalent system running with
* RSA. Just check out the "signs" statistics from the RSA and DSA parts
* of "openssl speed -engine atalla dsa1024 rsa1024". */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_atalla.c#L544-L562 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | atalla_mod_exp_mont | static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
{
return atalla_mod_exp(r, a, p, m, ctx);
} | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_atalla.c#L574-L578 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | atalla_mod_exp_dh | static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r,
const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
{
return atalla_mod_exp(r, a, p, m, ctx);
} | /* This function is aliased to mod_exp (with the dh and mont dropped). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_atalla.c#L583-L588 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | capi_rsa_priv_enc | int capi_rsa_priv_enc(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
CAPIerr(CAPI_F_CAPI_RSA_PRIV_ENC, CAPI_R_FUNCTION_NOT_SUPPORTED);
return -1;
} | /* CryptoAPI RSA operations */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_capi.c#L779-L784 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | cert_select_simple | static int cert_select_simple(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs)
{
return 0;
} | /* Simple client cert selection function: always select first */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_capi.c#L1717-L1720 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | bind_helper | static int bind_helper(ENGINE *e)
{
#ifndef OPENSSL_NO_RSA
const RSA_METHOD *meth1;
#endif
#ifndef OPENSSL_NO_DH
const DH_METHOD *meth2;
#endif
if(!ENGINE_set_id(e, engine_hwcrhk_id) ||
!ENGINE_set_name(e, engine_hwcrhk_name) ||
#ifndef OPENSSL_NO_RSA
!ENGINE_set_RSA(e, &hwcrhk_rsa) ||
#endif
#ifndef OPENSSL_NO_DH
!ENGINE_set_DH(e, &hwcrhk_dh) ||
#endif
!ENGINE_set_RAND(e, &hwcrhk_rand) ||
!ENGINE_set_destroy_function(e, hwcrhk_destroy) ||
!ENGINE_set_init_function(e, hwcrhk_init) ||
!ENGINE_set_finish_function(e, hwcrhk_finish) ||
!ENGINE_set_ctrl_function(e, hwcrhk_ctrl) ||
!ENGINE_set_load_privkey_function(e, hwcrhk_load_privkey) ||
!ENGINE_set_load_pubkey_function(e, hwcrhk_load_pubkey) ||
!ENGINE_set_cmd_defns(e, hwcrhk_cmd_defns))
return 0;
#ifndef OPENSSL_NO_RSA
/* We know that the "PKCS1_SSLeay()" functions hook properly
* to the cswift-specific mod_exp and mod_exp_crt so we use
* those functions. NB: We don't use ENGINE_openssl() or
* anything "more generic" because something like the RSAref
* code may not hook properly, and if you own one of these
* cards then you have the right to do RSA operations on it
* anyway! */
meth1 = RSA_PKCS1_SSLeay();
hwcrhk_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
hwcrhk_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
hwcrhk_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
hwcrhk_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
#endif
#ifndef OPENSSL_NO_DH
/* Much the same for Diffie-Hellman */
meth2 = DH_OpenSSL();
hwcrhk_dh.generate_key = meth2->generate_key;
hwcrhk_dh.compute_key = meth2->compute_key;
#endif
/* Ensure the hwcrhk error handling is set up */
ERR_load_HWCRHK_strings();
return 1;
} | /* Now, to our own code */
/* This internal function is used by ENGINE_chil() and possibly by the
* "dynamic" ENGINE support too */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_chil.c#L335-L386 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_context | static int get_context(HWCryptoHook_ContextHandle *hac,
HWCryptoHook_CallerContext *cac)
{
char tempbuf[1024];
HWCryptoHook_ErrMsgBuf rmsg;
rmsg.buf = tempbuf;
rmsg.size = sizeof(tempbuf);
*hac = p_hwcrhk_Init(&hwcrhk_globals, sizeof(hwcrhk_globals), &rmsg,
cac);
if (!*hac)
return 0;
return 1;
} | /* HWCryptoHook library functions and mechanics - these are used by the
* higher-level functions further down. NB: As and where there's no
* error checking, take a look lower down where these functions are
* called, the checking and error handling is probably down there. */
/* utility function to obtain a context */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_chil.c#L479-L493 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | release_context | static void release_context(HWCryptoHook_ContextHandle hac)
{
p_hwcrhk_Finish(hac);
} | /* similarly to release one. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_chil.c#L496-L499 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | hwcrhk_destroy | static int hwcrhk_destroy(ENGINE *e)
{
free_HWCRHK_LIBNAME();
ERR_unload_HWCRHK_strings();
return 1;
} | /* Destructor (complements the "ENGINE_chil()" constructor) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_chil.c#L502-L507 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | hwcrhk_init | static int hwcrhk_init(ENGINE *e)
{
HWCryptoHook_Init_t *p1;
HWCryptoHook_Finish_t *p2;
HWCryptoHook_ModExp_t *p3;
#ifndef OPENSSL_NO_RSA
HWCryptoHook_RSA_t *p4;
HWCryptoHook_RSALoadKey_t *p5;
HWCryptoHook_RSAGetPublicKey_t *p6;
HWCryptoHook_RSAUnloadKey_t *p7;
#endif
HWCryptoHook_RandomBytes_t *p8;
HWCryptoHook_ModExpCRT_t *p9;
if(hwcrhk_dso != NULL)
{
HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_ALREADY_LOADED);
goto err;
}
/* Attempt to load libnfhwcrhk.so/nfhwcrhk.dll/whatever. */
hwcrhk_dso = DSO_load(NULL, get_HWCRHK_LIBNAME(), NULL, 0);
if(hwcrhk_dso == NULL)
{
HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE);
goto err;
}
if(!(p1 = (HWCryptoHook_Init_t *)
DSO_bind_func(hwcrhk_dso, n_hwcrhk_Init)) ||
!(p2 = (HWCryptoHook_Finish_t *)
DSO_bind_func(hwcrhk_dso, n_hwcrhk_Finish)) ||
!(p3 = (HWCryptoHook_ModExp_t *)
DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExp)) ||
#ifndef OPENSSL_NO_RSA
!(p4 = (HWCryptoHook_RSA_t *)
DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSA)) ||
!(p5 = (HWCryptoHook_RSALoadKey_t *)
DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSALoadKey)) ||
!(p6 = (HWCryptoHook_RSAGetPublicKey_t *)
DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAGetPublicKey)) ||
!(p7 = (HWCryptoHook_RSAUnloadKey_t *)
DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAUnloadKey)) ||
#endif
!(p8 = (HWCryptoHook_RandomBytes_t *)
DSO_bind_func(hwcrhk_dso, n_hwcrhk_RandomBytes)) ||
!(p9 = (HWCryptoHook_ModExpCRT_t *)
DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExpCRT)))
{
HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE);
goto err;
}
/* Copy the pointers */
p_hwcrhk_Init = p1;
p_hwcrhk_Finish = p2;
p_hwcrhk_ModExp = p3;
#ifndef OPENSSL_NO_RSA
p_hwcrhk_RSA = p4;
p_hwcrhk_RSALoadKey = p5;
p_hwcrhk_RSAGetPublicKey = p6;
p_hwcrhk_RSAUnloadKey = p7;
#endif
p_hwcrhk_RandomBytes = p8;
p_hwcrhk_ModExpCRT = p9;
/* Check if the application decided to support dynamic locks,
and if it does, use them. */
if (disable_mutex_callbacks == 0)
{
if (CRYPTO_get_dynlock_create_callback() != NULL &&
CRYPTO_get_dynlock_lock_callback() != NULL &&
CRYPTO_get_dynlock_destroy_callback() != NULL)
{
hwcrhk_globals.mutex_init = hwcrhk_mutex_init;
hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock;
hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock;
hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy;
}
}
/* Try and get a context - if not, we may have a DSO but no
* accelerator! */
if(!get_context(&hwcrhk_context, &password_context))
{
HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_UNIT_FAILURE);
goto err;
}
/* Everything's fine. */
#ifndef OPENSSL_NO_RSA
if (hndidx_rsa == -1)
hndidx_rsa = RSA_get_ex_new_index(0,
"nFast HWCryptoHook RSA key handle",
NULL, NULL, NULL);
#endif
return 1;
err:
if(hwcrhk_dso)
DSO_free(hwcrhk_dso);
hwcrhk_dso = NULL;
p_hwcrhk_Init = NULL;
p_hwcrhk_Finish = NULL;
p_hwcrhk_ModExp = NULL;
#ifndef OPENSSL_NO_RSA
p_hwcrhk_RSA = NULL;
p_hwcrhk_RSALoadKey = NULL;
p_hwcrhk_RSAGetPublicKey = NULL;
p_hwcrhk_RSAUnloadKey = NULL;
#endif
p_hwcrhk_ModExpCRT = NULL;
p_hwcrhk_RandomBytes = NULL;
return 0;
} | /* (de)initialisation functions. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_chil.c#L510-L619 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | hwcrhk_mod_exp | static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx)
{
char tempbuf[1024];
HWCryptoHook_ErrMsgBuf rmsg;
/* Since HWCryptoHook_MPI is pretty compatible with BIGNUM's,
we use them directly, plus a little macro magic. We only
thing we need to make sure of is that enough space is allocated. */
HWCryptoHook_MPI m_a, m_p, m_n, m_r;
int to_return, ret;
to_return = 0; /* expect failure */
rmsg.buf = tempbuf;
rmsg.size = sizeof(tempbuf);
if(!hwcrhk_context)
{
HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_NOT_INITIALISED);
goto err;
}
/* Prepare the params */
bn_expand2(r, m->top); /* Check for error !! */
BN2MPI(m_a, a);
BN2MPI(m_p, p);
BN2MPI(m_n, m);
MPI2BN(r, m_r);
/* Perform the operation */
ret = p_hwcrhk_ModExp(hwcrhk_context, m_a, m_p, m_n, &m_r, &rmsg);
/* Convert the response */
r->top = m_r.size / sizeof(BN_ULONG);
bn_fix_top(r);
if (ret < 0)
{
/* FIXME: When this error is returned, HWCryptoHook is
telling us that falling back to software computation
might be a good thing. */
if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
{
HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_REQUEST_FALLBACK);
}
else
{
HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_REQUEST_FAILED);
}
ERR_add_error_data(1,rmsg.buf);
goto err;
}
to_return = 1;
err:
return to_return;
} | /* A little mod_exp */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_chil.c#L895-L949 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | hwcrhk_mod_exp_mont | static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
{
return hwcrhk_mod_exp(r, a, p, m, ctx);
} | /* This function is aliased to mod_exp (with the mont stuff dropped). */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/engines/e_chil.c#L1071-L1075 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.