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 | obj_name_hash | static unsigned long obj_name_hash(const void *a_void)
{
unsigned long ret;
const OBJ_NAME *a = (const OBJ_NAME *)a_void;
if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
{
ret=sk_NAME_FUNCS_value(name_funcs_stack,
a->type)->hash_func(a->name);
}
else
{
ret=lh_strhash(a->name);
}
ret^=a->type;
return(ret);
} | /* static unsigned long obj_name_hash(OBJ_NAME *a) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/objects/o_names.c#L137-L153 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_request_set1_name | int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm)
{
GENERAL_NAME *gen;
gen = GENERAL_NAME_new();
if (gen == NULL)
return 0;
if (!X509_NAME_set(&gen->d.directoryName, nm))
{
GENERAL_NAME_free(gen);
return 0;
}
gen->type = GEN_DIRNAME;
if (req->tbsRequest->requestorName)
GENERAL_NAME_free(req->tbsRequest->requestorName);
req->tbsRequest->requestorName = gen;
return 1;
} | /* Set requestorName from an X509_NAME structure */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_cl.c#L100-L116 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_request_add1_cert | int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert)
{
OCSP_SIGNATURE *sig;
if (!req->optionalSignature)
req->optionalSignature = OCSP_SIGNATURE_new();
sig = req->optionalSignature;
if (!sig) return 0;
if (!cert) return 1;
if (!sig->certs && !(sig->certs = sk_X509_new_null()))
return 0;
if(!sk_X509_push(sig->certs, cert)) return 0;
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
return 1;
} | /* Add a certificate to an OCSP request */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_cl.c#L121-L135 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_request_sign | int OCSP_request_sign(OCSP_REQUEST *req,
X509 *signer,
EVP_PKEY *key,
const EVP_MD *dgst,
STACK_OF(X509) *certs,
unsigned long flags)
{
int i;
OCSP_SIGNATURE *sig;
X509 *x;
if (!OCSP_request_set1_name(req, X509_get_subject_name(signer)))
goto err;
if (!(req->optionalSignature = sig = OCSP_SIGNATURE_new())) goto err;
if (key)
{
if (!X509_check_private_key(signer, key))
{
OCSPerr(OCSP_F_OCSP_REQUEST_SIGN, OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
goto err;
}
if (!OCSP_REQUEST_sign(req, key, dgst)) goto err;
}
if (!(flags & OCSP_NOCERTS))
{
if(!OCSP_request_add1_cert(req, signer)) goto err;
for (i = 0; i < sk_X509_num(certs); i++)
{
x = sk_X509_value(certs, i);
if (!OCSP_request_add1_cert(req, x)) goto err;
}
}
return 1;
err:
OCSP_SIGNATURE_free(req->optionalSignature);
req->optionalSignature = NULL;
return 0;
} | /* Sign an OCSP request set the requestorName to the subjec
* name of an optional signers certificate and include one
* or more optional certificates in the request. Behaves
* like PKCS7_sign().
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_cl.c#L143-L183 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_response_status | int OCSP_response_status(OCSP_RESPONSE *resp)
{
return ASN1_ENUMERATED_get(resp->responseStatus);
} | /* Get response status */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_cl.c#L187-L190 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_resp_count | int OCSP_resp_count(OCSP_BASICRESP *bs)
{
if (!bs) return -1;
return sk_OCSP_SINGLERESP_num(bs->tbsResponseData->responses);
} | /* Return number of OCSP_SINGLERESP reponses present in
* a basic response.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_cl.c#L219-L223 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_resp_find | int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last)
{
int i;
STACK_OF(OCSP_SINGLERESP) *sresp;
OCSP_SINGLERESP *single;
if (!bs) return -1;
if (last < 0) last = 0;
else last++;
sresp = bs->tbsResponseData->responses;
for (i = last; i < sk_OCSP_SINGLERESP_num(sresp); i++)
{
single = sk_OCSP_SINGLERESP_value(sresp, i);
if (!OCSP_id_cmp(id, single->certId)) return i;
}
return -1;
} | /* Look single response matching a given certificate ID */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_cl.c#L235-L250 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_single_get0_status | int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
ASN1_GENERALIZEDTIME **revtime,
ASN1_GENERALIZEDTIME **thisupd,
ASN1_GENERALIZEDTIME **nextupd)
{
int ret;
OCSP_CERTSTATUS *cst;
if(!single) return -1;
cst = single->certStatus;
ret = cst->type;
if (ret == V_OCSP_CERTSTATUS_REVOKED)
{
OCSP_REVOKEDINFO *rev = cst->value.revoked;
if (revtime) *revtime = rev->revocationTime;
if (reason)
{
if(rev->revocationReason)
*reason = ASN1_ENUMERATED_get(rev->revocationReason);
else *reason = -1;
}
}
if(thisupd) *thisupd = single->thisUpdate;
if(nextupd) *nextupd = single->nextUpdate;
return ret;
} | /* Extract status information from an OCSP_SINGLERESP structure.
* Note: the revtime and reason values are only set if the
* certificate status is revoked. Returns numerical value of
* status.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_cl.c#L258-L282 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_resp_find_status | int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
int *reason,
ASN1_GENERALIZEDTIME **revtime,
ASN1_GENERALIZEDTIME **thisupd,
ASN1_GENERALIZEDTIME **nextupd)
{
int i;
OCSP_SINGLERESP *single;
i = OCSP_resp_find(bs, id, -1);
/* Maybe check for multiple responses and give an error? */
if(i < 0) return 0;
single = OCSP_resp_get0(bs, i);
i = OCSP_single_get0_status(single, reason, revtime, thisupd, nextupd);
if(status) *status = i;
return 1;
} | /* This function combines the previous ones: look up a certificate ID and
* if found extract status information. Return 0 is successful.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_cl.c#L288-L303 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_check_validity | int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd, ASN1_GENERALIZEDTIME *nextupd, long nsec, long maxsec)
{
int ret = 1;
time_t t_now, t_tmp;
time(&t_now);
/* Check thisUpdate is valid and not more than nsec in the future */
if (!ASN1_GENERALIZEDTIME_check(thisupd))
{
OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_THISUPDATE_FIELD);
ret = 0;
}
else
{
t_tmp = t_now + nsec;
if (X509_cmp_time(thisupd, &t_tmp) > 0)
{
OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_NOT_YET_VALID);
ret = 0;
}
/* If maxsec specified check thisUpdate is not more than maxsec in the past */
if (maxsec >= 0)
{
t_tmp = t_now - maxsec;
if (X509_cmp_time(thisupd, &t_tmp) < 0)
{
OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_TOO_OLD);
ret = 0;
}
}
}
if (!nextupd) return ret;
/* Check nextUpdate is valid and not more than nsec in the past */
if (!ASN1_GENERALIZEDTIME_check(nextupd))
{
OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_ERROR_IN_NEXTUPDATE_FIELD);
ret = 0;
}
else
{
t_tmp = t_now - nsec;
if (X509_cmp_time(nextupd, &t_tmp) < 0)
{
OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_STATUS_EXPIRED);
ret = 0;
}
}
/* Also don't allow nextUpdate to precede thisUpdate */
if (ASN1_STRING_cmp(nextupd, thisupd) < 0)
{
OCSPerr(OCSP_F_OCSP_CHECK_VALIDITY, OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE);
ret = 0;
}
return ret;
} | /* Check validity of thisUpdate and nextUpdate fields. It is possible that the request will
* take a few seconds to process and/or the time wont be totally accurate. Therefore to avoid
* rejecting otherwise valid time we allow the times to be within 'nsec' of the current time.
* Also to avoid accepting very old responses without a nextUpdate field an optional maxage
* parameter specifies the maximum age the thisUpdate field can be.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_cl.c#L312-L371 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_REQUEST_get_ext_count | int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x)
{
return(X509v3_get_ext_count(x->tbsRequest->requestExtensions));
} | /* Standard wrapper functions for extensions */
/* OCSP request extensions */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ext.c#L76-L79 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_ONEREQ_get_ext_count | int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x)
{
return(X509v3_get_ext_count(x->singleRequestExtensions));
} | /* Single extensions */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ext.c#L124-L127 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_BASICRESP_get_ext_count | int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x)
{
return(X509v3_get_ext_count(x->tbsResponseData->responseExtensions));
} | /* OCSP Basic response */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ext.c#L172-L175 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_SINGLERESP_get_ext_count | int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x)
{
return(X509v3_get_ext_count(x->singleExtensions));
} | /* OCSP single response extensions */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ext.c#L220-L223 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ocsp_add1_nonce | static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len)
{
unsigned char *tmpval;
ASN1_OCTET_STRING os;
int ret = 0;
if (len <= 0) len = OCSP_DEFAULT_NONCE_LENGTH;
/* Create the OCTET STRING manually by writing out the header and
* appending the content octets. This avoids an extra memory allocation
* operation in some cases. Applications should *NOT* do this because
* it relies on library internals.
*/
os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING);
os.data = OPENSSL_malloc(os.length);
if (os.data == NULL)
goto err;
tmpval = os.data;
ASN1_put_object(&tmpval, 0, len, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL);
if (val)
memcpy(tmpval, val, len);
else
RAND_pseudo_bytes(tmpval, len);
if(!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce,
&os, 0, X509V3_ADD_REPLACE))
goto err;
ret = 1;
err:
if (os.data)
OPENSSL_free(os.data);
return ret;
} | /* Nonce handling functions */
/* Add a nonce to an extension stack. A nonce can be specificed or if NULL
* a random nonce will be generated.
* Note: OpenSSL 0.9.7d and later create an OCTET STRING containing the
* nonce, previous versions used the raw nonce.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ext.c#L318-L347 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_request_add1_nonce | int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len)
{
return ocsp_add1_nonce(&req->tbsRequest->requestExtensions, val, len);
} | /* Add nonce to an OCSP request */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ext.c#L352-L355 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_basic_add1_nonce | int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len)
{
return ocsp_add1_nonce(&resp->tbsResponseData->responseExtensions, val, len);
} | /* Same as above but for a response */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ext.c#L359-L362 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_check_nonce | int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs)
{
/*
* Since we are only interested in the presence or absence of
* the nonce and comparing its value there is no need to use
* the X509V3 routines: this way we can avoid them allocating an
* ASN1_OCTET_STRING structure for the value which would be
* freed immediately anyway.
*/
int req_idx, resp_idx;
X509_EXTENSION *req_ext, *resp_ext;
req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
resp_idx = OCSP_BASICRESP_get_ext_by_NID(bs, NID_id_pkix_OCSP_Nonce, -1);
/* Check both absent */
if((req_idx < 0) && (resp_idx < 0))
return 2;
/* Check in request only */
if((req_idx >= 0) && (resp_idx < 0))
return -1;
/* Check in response but not request */
if((req_idx < 0) && (resp_idx >= 0))
return 3;
/* Otherwise nonce in request and response so retrieve the extensions */
req_ext = OCSP_REQUEST_get_ext(req, req_idx);
resp_ext = OCSP_BASICRESP_get_ext(bs, resp_idx);
if(ASN1_OCTET_STRING_cmp(req_ext->value, resp_ext->value))
return 0;
return 1;
} | /* Check nonce validity in a request and response.
* Return value reflects result:
* 1: nonces present and equal.
* 2: nonces both absent.
* 3: nonce present in response only.
* 0: nonces both present and not equal.
* -1: nonce in request only.
*
* For most responders clients can check return > 0.
* If responder doesn't handle nonces return != 0 may be
* necessary. return == 0 is always an error.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ext.c#L377-L406 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_copy_nonce | int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req)
{
X509_EXTENSION *req_ext;
int req_idx;
/* Check for nonce in request */
req_idx = OCSP_REQUEST_get_ext_by_NID(req, NID_id_pkix_OCSP_Nonce, -1);
/* If no nonce that's OK */
if (req_idx < 0) return 2;
req_ext = OCSP_REQUEST_get_ext(req, req_idx);
return OCSP_BASICRESP_add_ext(resp, req_ext, -1);
} | /* Copy the nonce value (if any) from an OCSP request to
* a response.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ext.c#L412-L422 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | parse_http_line1 | static int parse_http_line1(char *line)
{
int retcode;
char *p, *q, *r;
/* Skip to first white space (passed protocol info) */
for(p = line; *p && !isspace((unsigned char)*p); p++)
continue;
if(!*p)
{
OCSPerr(OCSP_F_PARSE_HTTP_LINE1,
OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
return 0;
}
/* Skip past white space to start of response code */
while(*p && isspace((unsigned char)*p))
p++;
if(!*p)
{
OCSPerr(OCSP_F_PARSE_HTTP_LINE1,
OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
return 0;
}
/* Find end of response code: first whitespace after start of code */
for(q = p; *q && !isspace((unsigned char)*q); q++)
continue;
if(!*q)
{
OCSPerr(OCSP_F_PARSE_HTTP_LINE1,
OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
return 0;
}
/* Set end of response code and start of message */
*q++ = 0;
/* Attempt to parse numeric code */
retcode = strtoul(p, &r, 10);
if(*r)
return 0;
/* Skip over any leading white space in message */
while(*q && isspace((unsigned char)*q))
q++;
if(*q)
{
/* Finally zap any trailing white space in message (include
* CRLF) */
/* We know q has a non white space character so this is OK */
for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--)
*r = 0;
}
if(retcode != 200)
{
OCSPerr(OCSP_F_PARSE_HTTP_LINE1, OCSP_R_SERVER_RESPONSE_ERROR);
if(!*q)
ERR_add_error_data(2, "Code=", p);
else
ERR_add_error_data(4, "Code=", p, ",Reason=", q);
return 0;
}
return 1;
} | /* Parse the HTTP response. This will look like this:
* "HTTP/1.0 200 OK". We need to obtain the numeric code and
* (optional) informational message.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_ht.c#L189-L261 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_parse_url | int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pssl)
{
char *p, *buf;
char *host, *port;
/* dup the buffer since we are going to mess with it */
buf = BUF_strdup(url);
if (!buf) goto mem_err;
*phost = NULL;
*pport = NULL;
*ppath = NULL;
/* Check for initial colon */
p = strchr(buf, ':');
if (!p) goto parse_err;
*(p++) = '\0';
if (!strcmp(buf, "http"))
{
*pssl = 0;
port = "80";
}
else if (!strcmp(buf, "https"))
{
*pssl = 1;
port = "443";
}
else
goto parse_err;
/* Check for double slash */
if ((p[0] != '/') || (p[1] != '/'))
goto parse_err;
p += 2;
host = p;
/* Check for trailing part of path */
p = strchr(p, '/');
if (!p)
*ppath = BUF_strdup("/");
else
{
*ppath = BUF_strdup(p);
/* Set start of path to 0 so hostname is valid */
*p = '\0';
}
if (!*ppath) goto mem_err;
/* Look for optional ':' for port number */
if ((p = strchr(host, ':')))
{
*p = 0;
port = p + 1;
}
else
{
/* Not found: set default port */
if (*pssl) port = "443";
else port = "80";
}
*pport = BUF_strdup(port);
if (!*pport) goto mem_err;
*phost = BUF_strdup(host);
if (!*phost) goto mem_err;
OPENSSL_free(buf);
return 1;
mem_err:
OCSPerr(OCSP_F_OCSP_PARSE_URL, ERR_R_MALLOC_FAILURE);
goto err;
parse_err:
OCSPerr(OCSP_F_OCSP_PARSE_URL, OCSP_R_ERROR_PARSING_URL);
err:
if (buf) OPENSSL_free(buf);
if (*ppath) OPENSSL_free(*ppath);
if (*pport) OPENSSL_free(*pport);
if (*phost) OPENSSL_free(*phost);
return 0;
} | /* Parse a URL and split it up into host, port and path components and whether
* it is SSL.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_lib.c#L167-L263 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_request_onereq_count | int OCSP_request_onereq_count(OCSP_REQUEST *req)
{
return sk_OCSP_ONEREQ_num(req->tbsRequest->requestList);
} | /* Utility functions related to sending OCSP responses and extracting
* relevant information from the request.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_srv.c#L72-L75 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_basic_add1_cert | int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert)
{
if (!resp->certs && !(resp->certs = sk_X509_new_null()))
return 0;
if(!sk_X509_push(resp->certs, cert)) return 0;
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
return 1;
} | /* Add a certificate to an OCSP request */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_srv.c#L198-L206 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_basic_verify | int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
X509_STORE *st, unsigned long flags)
{
X509 *signer, *x;
STACK_OF(X509) *chain = NULL;
X509_STORE_CTX ctx;
int i, ret = 0;
ret = ocsp_find_signer(&signer, bs, certs, st, flags);
if (!ret)
{
OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
goto end;
}
if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
flags |= OCSP_NOVERIFY;
if (!(flags & OCSP_NOSIGS))
{
EVP_PKEY *skey;
skey = X509_get_pubkey(signer);
ret = OCSP_BASICRESP_verify(bs, skey, 0);
EVP_PKEY_free(skey);
if(ret <= 0)
{
OCSPerr(OCSP_F_OCSP_BASIC_VERIFY, OCSP_R_SIGNATURE_FAILURE);
goto end;
}
}
if (!(flags & OCSP_NOVERIFY))
{
int init_res;
if(flags & OCSP_NOCHAIN)
init_res = X509_STORE_CTX_init(&ctx, st, signer, NULL);
else
init_res = X509_STORE_CTX_init(&ctx, st, signer, bs->certs);
if(!init_res)
{
OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,ERR_R_X509_LIB);
goto end;
}
X509_STORE_CTX_set_purpose(&ctx, X509_PURPOSE_OCSP_HELPER);
ret = X509_verify_cert(&ctx);
chain = X509_STORE_CTX_get1_chain(&ctx);
X509_STORE_CTX_cleanup(&ctx);
if (ret <= 0)
{
i = X509_STORE_CTX_get_error(&ctx);
OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,OCSP_R_CERTIFICATE_VERIFY_ERROR);
ERR_add_error_data(2, "Verify error:",
X509_verify_cert_error_string(i));
goto end;
}
if(flags & OCSP_NOCHECKS)
{
ret = 1;
goto end;
}
/* At this point we have a valid certificate chain
* need to verify it against the OCSP issuer criteria.
*/
ret = ocsp_check_issuer(bs, chain, flags);
/* If fatal error or valid match then finish */
if (ret != 0) goto end;
/* Easy case: explicitly trusted. Get root CA and
* check for explicit trust
*/
if(flags & OCSP_NOEXPLICIT) goto end;
x = sk_X509_value(chain, sk_X509_num(chain) - 1);
if(X509_check_trust(x, NID_OCSP_sign, 0) != X509_TRUST_TRUSTED)
{
OCSPerr(OCSP_F_OCSP_BASIC_VERIFY,OCSP_R_ROOT_CA_NOT_TRUSTED);
goto end;
}
ret = 1;
}
end:
if(chain) sk_X509_pop_free(chain, X509_free);
return ret;
} | /* Verify a basic response message */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_vfy.c#L75-L159 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ocsp_check_ids | static int ocsp_check_ids(STACK_OF(OCSP_SINGLERESP) *sresp, OCSP_CERTID **ret)
{
OCSP_CERTID *tmpid, *cid;
int i, idcount;
idcount = sk_OCSP_SINGLERESP_num(sresp);
if (idcount <= 0)
{
OCSPerr(OCSP_F_OCSP_CHECK_IDS, OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA);
return -1;
}
cid = sk_OCSP_SINGLERESP_value(sresp, 0)->certId;
*ret = NULL;
for (i = 1; i < idcount; i++)
{
tmpid = sk_OCSP_SINGLERESP_value(sresp, i)->certId;
/* Check to see if IDs match */
if (OCSP_id_issuer_cmp(cid, tmpid))
{
/* If algoritm mismatch let caller deal with it */
if (OBJ_cmp(tmpid->hashAlgorithm->algorithm,
cid->hashAlgorithm->algorithm))
return 2;
/* Else mismatch */
return 0;
}
}
/* All IDs match: only need to check one ID */
*ret = cid;
return 1;
} | /* Check the issuer certificate IDs for equality. If there is a mismatch with the same
* algorithm then there's no point trying to match any certificates against the issuer.
* If the issuer IDs all match then we just need to check equality against one of them.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_vfy.c#L257-L291 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | OCSP_request_verify | int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *store, unsigned long flags)
{
X509 *signer;
X509_NAME *nm;
GENERAL_NAME *gen;
int ret;
X509_STORE_CTX ctx;
if (!req->optionalSignature)
{
OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_REQUEST_NOT_SIGNED);
return 0;
}
gen = req->tbsRequest->requestorName;
if (!gen || gen->type != GEN_DIRNAME)
{
OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE);
return 0;
}
nm = gen->d.directoryName;
ret = ocsp_req_find_signer(&signer, req, nm, certs, store, flags);
if (ret <= 0)
{
OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND);
return 0;
}
if ((ret == 2) && (flags & OCSP_TRUSTOTHER))
flags |= OCSP_NOVERIFY;
if (!(flags & OCSP_NOSIGS))
{
EVP_PKEY *skey;
skey = X509_get_pubkey(signer);
ret = OCSP_REQUEST_verify(req, skey);
EVP_PKEY_free(skey);
if(ret <= 0)
{
OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_SIGNATURE_FAILURE);
return 0;
}
}
if (!(flags & OCSP_NOVERIFY))
{
int init_res;
if(flags & OCSP_NOCHAIN)
init_res = X509_STORE_CTX_init(&ctx, store, signer, NULL);
else
init_res = X509_STORE_CTX_init(&ctx, store, signer,
req->optionalSignature->certs);
if(!init_res)
{
OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY,ERR_R_X509_LIB);
return 0;
}
X509_STORE_CTX_set_purpose(&ctx, X509_PURPOSE_OCSP_HELPER);
X509_STORE_CTX_set_trust(&ctx, X509_TRUST_OCSP_REQUEST);
ret = X509_verify_cert(&ctx);
X509_STORE_CTX_cleanup(&ctx);
if (ret <= 0)
{
ret = X509_STORE_CTX_get_error(&ctx);
OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY,OCSP_R_CERTIFICATE_VERIFY_ERROR);
ERR_add_error_data(2, "Verify error:",
X509_verify_cert_error_string(ret));
return 0;
}
}
return 1;
} | /* Verify an OCSP request. This is fortunately much easier than OCSP
* response verify. Just find the signers certificate and verify it
* against a given trust value.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ocsp/ocsp_vfy.c#L359-L426 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PEM_X509_INFO_write_bio | int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
{
EVP_CIPHER_CTX ctx;
int i,ret=0;
unsigned char *data=NULL;
const char *objstr=NULL;
char buf[PEM_BUFSIZE];
unsigned char *iv=NULL;
if (enc != NULL)
{
objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
if (objstr == NULL)
{
PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
goto err;
}
}
/* now for the fun part ... if we have a private key then
* we have to be able to handle a not-yet-decrypted key
* being written out correctly ... if it is decrypted or
* it is non-encrypted then we use the base code
*/
if (xi->x_pkey!=NULL)
{
if ( (xi->enc_data!=NULL) && (xi->enc_len>0) )
{
if (enc == NULL)
{
PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_CIPHER_IS_NULL);
goto err;
}
/* copy from weirdo names into more normal things */
iv=xi->enc_cipher.iv;
data=(unsigned char *)xi->enc_data;
i=xi->enc_len;
/* we take the encryption data from the
* internal stuff rather than what the
* user has passed us ... as we have to
* match exactly for some strange reason
*/
objstr=OBJ_nid2sn(
EVP_CIPHER_nid(xi->enc_cipher.cipher));
if (objstr == NULL)
{
PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
goto err;
}
/* create the right magic header stuff */
OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
buf[0]='\0';
PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
/* use the normal code to write things out */
i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);
if (i <= 0) goto err;
}
else
{
/* Add DSA/DH */
#ifndef OPENSSL_NO_RSA
/* normal optionally encrypted stuff */
if (PEM_write_bio_RSAPrivateKey(bp,
xi->x_pkey->dec_pkey->pkey.rsa,
enc,kstr,klen,cb,u)<=0)
goto err;
#endif
}
}
/* if we have a certificate then write it out now */
if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp,xi->x509) <= 0))
goto err;
/* we are ignoring anything else that is loaded into the X509_INFO
* structure for the moment ... as I don't need it so I'm not
* coding it here and Eric can do it when this makes it into the
* base library --tjh
*/
ret=1;
err:
OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
OPENSSL_cleanse(buf,PEM_BUFSIZE);
return(ret);
} | /* A TJH addition */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pem/pem_info.c#L313-L405 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | pem_check_suffix | int pem_check_suffix(const char *pem_str, const char *suffix)
{
int pem_len = strlen(pem_str);
int suffix_len = strlen(suffix);
const char *p;
if (suffix_len + 1 >= pem_len)
return 0;
p = pem_str + pem_len - suffix_len;
if (strcmp(p, suffix))
return 0;
p--;
if (*p != ' ')
return 0;
return p - pem_str;
} | /* Check pem string and return prefix length.
* If for example the pem_str == "RSA PRIVATE KEY" and suffix = "PRIVATE KEY"
* the return value is 3 for the string "RSA".
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pem/pem_lib.c#L837-L851 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PEM_write_bio_PKCS8PrivateKey_nid | int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
} | /* These functions write a private key in PKCS#8 format: it is a "drop in"
* replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'
* is NULL then it uses the unencrypted private key form. The 'nid' versions
* uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pem/pem_pk8.c#L84-L89 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | read_ledword | static unsigned int read_ledword(const unsigned char **in)
{
const unsigned char *p = *in;
unsigned int ret;
ret = *p++;
ret |= (*p++ << 8);
ret |= (*p++ << 16);
ret |= (*p++ << 24);
*in = p;
return ret;
} | /* Utility function: read a DWORD (4 byte unsigned integer) in little endian
* format
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pem/pvkfmt.c#L74-L84 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | read_lebn | static int read_lebn(const unsigned char **in, unsigned int nbyte, BIGNUM **r)
{
const unsigned char *p;
unsigned char *tmpbuf, *q;
unsigned int i;
p = *in + nbyte - 1;
tmpbuf = OPENSSL_malloc(nbyte);
if (!tmpbuf)
return 0;
q = tmpbuf;
for (i = 0; i < nbyte; i++)
*q++ = *p--;
*r = BN_bin2bn(tmpbuf, nbyte, NULL);
OPENSSL_free(tmpbuf);
if (*r)
{
*in += nbyte;
return 1;
}
else
return 0;
} | /* Read a BIGNUM in little endian format. The docs say that this should take up
* bitlen/8 bytes.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pem/pvkfmt.c#L90-L111 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS12_add_localkeyid | int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name,
int namelen)
{
if (X509at_add1_attr_by_NID(&bag->attrib, NID_localKeyID,
V_ASN1_OCTET_STRING, name, namelen))
return 1;
else
return 0;
} | /* Add a local keyid to a safebag */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_attr.c#L65-L73 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS8_add_keyusage | int PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
{
unsigned char us_val;
us_val = (unsigned char) usage;
if (X509at_add1_attr_by_NID(&p8->attributes, NID_key_usage,
V_ASN1_BIT_STRING, &us_val, 1))
return 1;
else
return 0;
} | /* Add key usage to PKCS#8 structure */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_attr.c#L77-L86 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS12_add_friendlyname_asc | int PKCS12_add_friendlyname_asc(PKCS12_SAFEBAG *bag, const char *name,
int namelen)
{
if (X509at_add1_attr_by_NID(&bag->attrib, NID_friendlyName,
MBSTRING_ASC, (unsigned char *)name, namelen))
return 1;
else
return 0;
} | /* Add a friendlyname to a safebag */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_attr.c#L90-L98 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS12_PBE_add | void PKCS12_PBE_add(void)
{
} | /* PKCS#12 PBE algorithms now in static table */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_crpt.c#L65-L67 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS12_parse | int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
STACK_OF(X509) **ca)
{
STACK_OF(X509) *ocerts = NULL;
X509 *x = NULL;
/* Check for NULL PKCS12 structure */
if(!p12)
{
PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
return 0;
}
if(pkey)
*pkey = NULL;
if(cert)
*cert = NULL;
/* Check the mac */
/* If password is zero length or NULL then try verifying both cases
* to determine which password is correct. The reason for this is that
* under PKCS#12 password based encryption no password and a zero length
* password are two different things...
*/
if(!pass || !*pass) {
if(PKCS12_verify_mac(p12, NULL, 0)) pass = NULL;
else if(PKCS12_verify_mac(p12, "", 0)) pass = "";
else {
PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE);
goto err;
}
} else if (!PKCS12_verify_mac(p12, pass, -1)) {
PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_MAC_VERIFY_FAILURE);
goto err;
}
/* Allocate stack for other certificates */
ocerts = sk_X509_new_null();
if (!ocerts)
{
PKCS12err(PKCS12_F_PKCS12_PARSE,ERR_R_MALLOC_FAILURE);
return 0;
}
if (!parse_pk12 (p12, pass, -1, pkey, ocerts))
{
PKCS12err(PKCS12_F_PKCS12_PARSE,PKCS12_R_PARSE_ERROR);
goto err;
}
while ((x = sk_X509_pop(ocerts)))
{
if (pkey && *pkey && cert && !*cert)
{
if (X509_check_private_key(x, *pkey))
{
*cert = x;
x = NULL;
}
}
if (ca && x)
{
if (!*ca)
*ca = sk_X509_new_null();
if (!*ca)
goto err;
if (!sk_X509_push(*ca, x))
goto err;
x = NULL;
}
if (x)
X509_free(x);
}
if (ocerts)
sk_X509_pop_free(ocerts, X509_free);
return 1;
err:
if (pkey && *pkey)
EVP_PKEY_free(*pkey);
if (cert && *cert)
X509_free(*cert);
if (x)
X509_free(*cert);
if (ocerts)
sk_X509_pop_free(ocerts, X509_free);
return 0;
} | /* Parse and decrypt a PKCS#12 structure returning user key, user cert
* and other (CA) certs. Note either ca should be NULL, *ca should be NULL,
* or it should point to a valid STACK structure. pkey and cert can be
* passed unitialised.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_kiss.c#L80-L175 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | parse_pk12 | static int parse_pk12(PKCS12 *p12, const char *pass, int passlen,
EVP_PKEY **pkey, STACK_OF(X509) *ocerts)
{
STACK_OF(PKCS7) *asafes;
STACK_OF(PKCS12_SAFEBAG) *bags;
int i, bagnid;
PKCS7 *p7;
if (!(asafes = PKCS12_unpack_authsafes (p12))) return 0;
for (i = 0; i < sk_PKCS7_num (asafes); i++) {
p7 = sk_PKCS7_value (asafes, i);
bagnid = OBJ_obj2nid (p7->type);
if (bagnid == NID_pkcs7_data) {
bags = PKCS12_unpack_p7data(p7);
} else if (bagnid == NID_pkcs7_encrypted) {
bags = PKCS12_unpack_p7encdata(p7, pass, passlen);
} else continue;
if (!bags) {
sk_PKCS7_pop_free(asafes, PKCS7_free);
return 0;
}
if (!parse_bags(bags, pass, passlen, pkey, ocerts)) {
sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
sk_PKCS7_pop_free(asafes, PKCS7_free);
return 0;
}
sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
}
sk_PKCS7_pop_free(asafes, PKCS7_free);
return 1;
} | /* Parse the outer PKCS#12 structure */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_kiss.c#L179-L209 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS12_gen_mac | int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
unsigned char *mac, unsigned int *maclen)
{
const EVP_MD *md_type;
HMAC_CTX hmac;
unsigned char key[EVP_MAX_MD_SIZE], *salt;
int saltlen, iter;
int md_size;
if (!PKCS7_type_is_data(p12->authsafes))
{
PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_CONTENT_TYPE_NOT_DATA);
return 0;
}
salt = p12->mac->salt->data;
saltlen = p12->mac->salt->length;
if (!p12->mac->iter) iter = 1;
else iter = ASN1_INTEGER_get (p12->mac->iter);
if(!(md_type =
EVP_get_digestbyobj (p12->mac->dinfo->algor->algorithm))) {
PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_UNKNOWN_DIGEST_ALGORITHM);
return 0;
}
md_size = EVP_MD_size(md_type);
if (md_size < 0)
return 0;
if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
md_size, key, md_type)) {
PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR);
return 0;
}
HMAC_CTX_init(&hmac);
HMAC_Init_ex(&hmac, key, md_size, md_type, NULL);
HMAC_Update(&hmac, p12->authsafes->d.data->data,
p12->authsafes->d.data->length);
HMAC_Final(&hmac, mac, maclen);
HMAC_CTX_cleanup(&hmac);
return 1;
} | /* Generate a MAC */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_mutl.c#L67-L106 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS12_verify_mac | int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen)
{
unsigned char mac[EVP_MAX_MD_SIZE];
unsigned int maclen;
if(p12->mac == NULL) {
PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC,PKCS12_R_MAC_ABSENT);
return 0;
}
if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC,PKCS12_R_MAC_GENERATION_ERROR);
return 0;
}
if ((maclen != (unsigned int)p12->mac->dinfo->digest->length)
|| memcmp (mac, p12->mac->dinfo->digest->data, maclen)) return 0;
return 1;
} | /* Verify the mac */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_mutl.c#L109-L124 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS12_set_mac | int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
unsigned char *salt, int saltlen, int iter, const EVP_MD *md_type)
{
unsigned char mac[EVP_MAX_MD_SIZE];
unsigned int maclen;
if (!md_type) md_type = EVP_sha1();
if (PKCS12_setup_mac (p12, iter, salt, saltlen, md_type) ==
PKCS12_ERROR) {
PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_SETUP_ERROR);
return 0;
}
if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_GENERATION_ERROR);
return 0;
}
if (!(M_ASN1_OCTET_STRING_set (p12->mac->dinfo->digest, mac, maclen))) {
PKCS12err(PKCS12_F_PKCS12_SET_MAC,PKCS12_R_MAC_STRING_SET_ERROR);
return 0;
}
return 1;
} | /* Set a mac */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_mutl.c#L128-L149 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS12_setup_mac | int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
const EVP_MD *md_type)
{
if (!(p12->mac = PKCS12_MAC_DATA_new())) return PKCS12_ERROR;
if (iter > 1) {
if(!(p12->mac->iter = M_ASN1_INTEGER_new())) {
PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
return 0;
}
if (!ASN1_INTEGER_set(p12->mac->iter, iter)) {
PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
return 0;
}
}
if (!saltlen) saltlen = PKCS12_SALT_LEN;
p12->mac->salt->length = saltlen;
if (!(p12->mac->salt->data = OPENSSL_malloc (saltlen))) {
PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
return 0;
}
if (!salt) {
if (RAND_pseudo_bytes (p12->mac->salt->data, saltlen) < 0)
return 0;
}
else memcpy (p12->mac->salt->data, salt, saltlen);
p12->mac->dinfo->algor->algorithm = OBJ_nid2obj(EVP_MD_type(md_type));
if (!(p12->mac->dinfo->algor->parameter = ASN1_TYPE_new())) {
PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
return 0;
}
p12->mac->dinfo->algor->parameter->type = V_ASN1_NULL;
return 1;
} | /* Set up a mac structure */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_mutl.c#L152-L185 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS12_newpass | int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass)
{
/* Check for NULL PKCS12 structure */
if(!p12) {
PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
return 0;
}
/* Check the mac */
if (!PKCS12_verify_mac(p12, oldpass, -1)) {
PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_MAC_VERIFY_FAILURE);
return 0;
}
if (!newpass_p12(p12, oldpass, newpass)) {
PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_PARSE_ERROR);
return 0;
}
return 1;
} | /*
* Change the password on a PKCS#12 structure.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_npas.c#L78-L100 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | newpass_p12 | static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass)
{
STACK_OF(PKCS7) *asafes, *newsafes;
STACK_OF(PKCS12_SAFEBAG) *bags;
int i, bagnid, pbe_nid = 0, pbe_iter = 0, pbe_saltlen = 0;
PKCS7 *p7, *p7new;
ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL;
unsigned char mac[EVP_MAX_MD_SIZE];
unsigned int maclen;
if (!(asafes = PKCS12_unpack_authsafes(p12))) return 0;
if(!(newsafes = sk_PKCS7_new_null())) return 0;
for (i = 0; i < sk_PKCS7_num (asafes); i++) {
p7 = sk_PKCS7_value(asafes, i);
bagnid = OBJ_obj2nid(p7->type);
if (bagnid == NID_pkcs7_data) {
bags = PKCS12_unpack_p7data(p7);
} else if (bagnid == NID_pkcs7_encrypted) {
bags = PKCS12_unpack_p7encdata(p7, oldpass, -1);
if (!alg_get(p7->d.encrypted->enc_data->algorithm,
&pbe_nid, &pbe_iter, &pbe_saltlen))
{
sk_PKCS12_SAFEBAG_pop_free(bags,
PKCS12_SAFEBAG_free);
bags = NULL;
}
} else continue;
if (!bags) {
sk_PKCS7_pop_free(asafes, PKCS7_free);
return 0;
}
if (!newpass_bags(bags, oldpass, newpass)) {
sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
sk_PKCS7_pop_free(asafes, PKCS7_free);
return 0;
}
/* Repack bag in same form with new password */
if (bagnid == NID_pkcs7_data) p7new = PKCS12_pack_p7data(bags);
else p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, NULL,
pbe_saltlen, pbe_iter, bags);
sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
if(!p7new) {
sk_PKCS7_pop_free(asafes, PKCS7_free);
return 0;
}
sk_PKCS7_push(newsafes, p7new);
}
sk_PKCS7_pop_free(asafes, PKCS7_free);
/* Repack safe: save old safe in case of error */
p12_data_tmp = p12->authsafes->d.data;
if(!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) goto saferr;
if(!PKCS12_pack_authsafes(p12, newsafes)) goto saferr;
if(!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr;
if(!(macnew = ASN1_OCTET_STRING_new())) goto saferr;
if(!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr;
ASN1_OCTET_STRING_free(p12->mac->dinfo->digest);
p12->mac->dinfo->digest = macnew;
ASN1_OCTET_STRING_free(p12_data_tmp);
return 1;
saferr:
/* Restore old safe */
ASN1_OCTET_STRING_free(p12->authsafes->d.data);
ASN1_OCTET_STRING_free(macnew);
p12->authsafes->d.data = p12_data_tmp;
return 0;
} | /* Parse the outer PKCS#12 structure */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_npas.c#L104-L175 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | newpass_bag | static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass)
{
PKCS8_PRIV_KEY_INFO *p8;
X509_SIG *p8new;
int p8_nid, p8_saltlen, p8_iter;
if(M_PKCS12_bag_type(bag) != NID_pkcs8ShroudedKeyBag) return 1;
if (!(p8 = PKCS8_decrypt(bag->value.shkeybag, oldpass, -1))) return 0;
if (!alg_get(bag->value.shkeybag->algor, &p8_nid, &p8_iter,
&p8_saltlen))
return 0;
if(!(p8new = PKCS8_encrypt(p8_nid, NULL, newpass, -1, NULL, p8_saltlen,
p8_iter, p8))) return 0;
X509_SIG_free(bag->value.shkeybag);
bag->value.shkeybag = p8new;
return 1;
} | /* Change password of safebag: only needs handle shrouded keybags */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs12/p12_npas.c#L192-L209 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | BIO_set_cipher | void BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *k, unsigned char *i,
int e)
{
BIO_ENC_CTX *ctx;
if (b == NULL) return;
if ((b->callback != NULL) &&
(b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
return;
b->init=1;
ctx=(BIO_ENC_CTX *)b->ptr;
EVP_CipherInit_ex(&(ctx->cipher),c,NULL,k,i,e);
if (b->callback != NULL)
b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
} | /*
void BIO_set_cipher_ctx(b,c)
BIO *b;
EVP_CIPHER_ctx *c;
{
if (b == NULL) return;
if ((b->callback != NULL) &&
(b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
return;
b->init=1;
ctx=(BIO_ENC_CTX *)b->ptr;
memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
if (b->callback != NULL)
b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
}
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/bio_ber.c#L448-L465 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | verify_callback | int verify_callback(int ok, X509_STORE_CTX *ctx)
{
char buf[256];
X509 *err_cert;
int err,depth;
err_cert=X509_STORE_CTX_get_current_cert(ctx);
err= X509_STORE_CTX_get_error(ctx);
depth= X509_STORE_CTX_get_error_depth(ctx);
X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
if (!ok)
{
BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
X509_verify_cert_error_string(err));
if (depth < 6)
{
ok=1;
X509_STORE_CTX_set_error(ctx,X509_V_OK);
}
else
{
ok=0;
X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
}
}
switch (ctx->error)
{
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
BIO_printf(bio_err,"issuer= %s\n",buf);
break;
case X509_V_ERR_CERT_NOT_YET_VALID:
case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
BIO_printf(bio_err,"notBefore=");
ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
BIO_printf(bio_err,"\n");
break;
case X509_V_ERR_CERT_HAS_EXPIRED:
case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
BIO_printf(bio_err,"notAfter=");
ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
BIO_printf(bio_err,"\n");
break;
}
BIO_printf(bio_err,"verify return:%d\n",ok);
return(ok);
} | /* should be X509 * but we can just have them as char *. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/dec.c#L200-L248 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | add_signed_seq2string | int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
{
/* To add an object of OID 1.9.999, which is a sequence containing
* 2 octet strings */
unsigned char *p;
ASN1_OCTET_STRING *os1,*os2;
ASN1_STRING *seq;
unsigned char *data;
int i,total;
if (signed_seq2string_nid == -1)
signed_seq2string_nid=
OBJ_create("1.9.9999","OID_example","Our example OID");
os1=ASN1_OCTET_STRING_new();
os2=ASN1_OCTET_STRING_new();
ASN1_OCTET_STRING_set(os1,(unsigned char*)str1,strlen(str1));
ASN1_OCTET_STRING_set(os2,(unsigned char*)str1,strlen(str1));
i =i2d_ASN1_OCTET_STRING(os1,NULL);
i+=i2d_ASN1_OCTET_STRING(os2,NULL);
total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
data=malloc(total);
p=data;
ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
i2d_ASN1_OCTET_STRING(os1,&p);
i2d_ASN1_OCTET_STRING(os2,&p);
seq=ASN1_STRING_new();
ASN1_STRING_set(seq,data,total);
free(data);
ASN1_OCTET_STRING_free(os1);
ASN1_OCTET_STRING_free(os2);
PKCS7_add_signed_attribute(si,signed_seq2string_nid,
V_ASN1_SEQUENCE,(char *)seq);
return(1);
} | /* ########################################### */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/example.c#L75-L112 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | get_signed_seq2string | int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2)
{
ASN1_TYPE *so;
if (signed_seq2string_nid == -1)
signed_seq2string_nid=
OBJ_create("1.9.9999","OID_example","Our example OID");
/* To retrieve */
so=PKCS7_get_signed_attribute(si,signed_seq2string_nid);
if (so && (so->type == V_ASN1_SEQUENCE))
{
ASN1_const_CTX c;
ASN1_STRING *s;
long length;
ASN1_OCTET_STRING *os1,*os2;
s=so->value.sequence;
c.p=ASN1_STRING_data(s);
c.max=c.p+ASN1_STRING_length(s);
if (!asn1_GetSequence(&c,&length)) goto err;
/* Length is the length of the seqence */
c.q=c.p;
if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
goto err;
c.slen-=(c.p-c.q);
c.q=c.p;
if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
goto err;
c.slen-=(c.p-c.q);
if (!asn1_const_Finish(&c)) goto err;
*str1=malloc(os1->length+1);
*str2=malloc(os2->length+1);
memcpy(*str1,os1->data,os1->length);
memcpy(*str2,os2->data,os2->length);
(*str1)[os1->length]='\0';
(*str2)[os2->length]='\0';
ASN1_OCTET_STRING_free(os1);
ASN1_OCTET_STRING_free(os2);
return(1);
}
err:
return(0);
} | /* For this case, I will malloc the return strings */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/example.c#L115-L160 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sk_get_seq2string | int sk_get_seq2string(STACK_OF(X509_ATTRIBUTE) *sk, char **str1, char **str2)
{
ASN1_TYPE *so;
PKCS7_SIGNER_INFO si;
if (signed_seq2string_nid == -1)
signed_seq2string_nid=
OBJ_create("1.9.9999","OID_example","Our example OID");
si.auth_attr=sk;
/* To retrieve */
so=PKCS7_get_signed_attribute(&si,signed_seq2string_nid);
if (so->type == V_ASN1_SEQUENCE)
{
ASN1_const_CTX c;
ASN1_STRING *s;
long length;
ASN1_OCTET_STRING *os1,*os2;
s=so->value.sequence;
c.p=ASN1_STRING_data(s);
c.max=c.p+ASN1_STRING_length(s);
if (!asn1_GetSequence(&c,&length)) goto err;
/* Length is the length of the seqence */
c.q=c.p;
if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
goto err;
c.slen-=(c.p-c.q);
c.q=c.p;
if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
goto err;
c.slen-=(c.p-c.q);
if (!asn1_const_Finish(&c)) goto err;
*str1=malloc(os1->length+1);
*str2=malloc(os2->length+1);
memcpy(*str1,os1->data,os1->length);
memcpy(*str2,os2->data,os2->length);
(*str1)[os1->length]='\0';
(*str2)[os2->length]='\0';
ASN1_OCTET_STRING_free(os1);
ASN1_OCTET_STRING_free(os2);
return(1);
}
err:
return(0);
} | /* For this case, I will malloc the return strings */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/example.c#L279-L327 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | pk7_cb | static int pk7_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
void *exarg)
{
ASN1_STREAM_ARG *sarg = exarg;
PKCS7 **pp7 = (PKCS7 **)pval;
switch(operation)
{
case ASN1_OP_STREAM_PRE:
if (PKCS7_stream(&sarg->boundary, *pp7) <= 0)
return 0;
case ASN1_OP_DETACHED_PRE:
sarg->ndef_bio = PKCS7_dataInit(*pp7, sarg->out);
if (!sarg->ndef_bio)
return 0;
break;
case ASN1_OP_STREAM_POST:
case ASN1_OP_DETACHED_POST:
if (PKCS7_dataFinal(*pp7, sarg->ndef_bio) <= 0)
return 0;
break;
}
return 1;
} | /* PKCS#7 streaming support */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/pk7_asn1.c#L81-L107 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | PKCS7_simple_smimecap | int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
{
X509_ALGOR *alg;
if(!(alg = X509_ALGOR_new())) {
PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
return 0;
}
ASN1_OBJECT_free(alg->algorithm);
alg->algorithm = OBJ_nid2obj (nid);
if (arg > 0) {
ASN1_INTEGER *nbit;
if(!(alg->parameter = ASN1_TYPE_new())) {
PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
return 0;
}
if(!(nbit = ASN1_INTEGER_new())) {
PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
return 0;
}
if(!ASN1_INTEGER_set (nbit, arg)) {
PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
return 0;
}
alg->parameter->value.integer = nbit;
alg->parameter->type = V_ASN1_INTEGER;
}
sk_X509_ALGOR_push (sk, alg);
return 1;
} | /* Basic smime-capabilities OID and optional integer arg */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/pk7_attr.c#L97-L126 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | i2d_PKCS7_bio_stream | int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags)
{
return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)p7, in, flags,
ASN1_ITEM_rptr(PKCS7));
} | /* PKCS#7 wrappers round generalised stream and MIME routines */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/pk7_mime.c#L64-L68 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | add_cipher_smcap | static int add_cipher_smcap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
{
if (EVP_get_cipherbynid(nid))
return PKCS7_simple_smimecap(sk, nid, arg);
return 1;
} | /* Check to see if a cipher exists and if so add S/MIME capabilities */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/pk7_smime.c#L147-L152 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | pkcs7_copy_existing_digest | static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
{
int i;
STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
PKCS7_SIGNER_INFO *sitmp;
ASN1_OCTET_STRING *osdig = NULL;
sinfos = PKCS7_get_signer_info(p7);
for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
{
sitmp = sk_PKCS7_SIGNER_INFO_value(sinfos, i);
if (si == sitmp)
break;
if (sk_X509_ATTRIBUTE_num(sitmp->auth_attr) <= 0)
continue;
if (!OBJ_cmp(si->digest_alg->algorithm,
sitmp->digest_alg->algorithm))
{
osdig = PKCS7_digest_from_attributes(sitmp->auth_attr);
break;
}
}
if (osdig)
return PKCS7_add1_attrib_digest(si, osdig->data, osdig->length);
PKCS7err(PKCS7_F_PKCS7_COPY_EXISTING_DIGEST,
PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND);
return 0;
} | /* Search for a digest matching SignerInfo digest type and if found
* copy across.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/pk7_smime.c#L235-L264 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | verify_callback | int verify_callback(int ok, X509_STORE_CTX *ctx)
{
char buf[256];
X509 *err_cert;
int err,depth;
err_cert=X509_STORE_CTX_get_current_cert(ctx);
err= X509_STORE_CTX_get_error(ctx);
depth= X509_STORE_CTX_get_error_depth(ctx);
X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
if (!ok)
{
BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
X509_verify_cert_error_string(err));
if (depth < 6)
{
ok=1;
X509_STORE_CTX_set_error(ctx,X509_V_OK);
}
else
{
ok=0;
X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
}
}
switch (ctx->error)
{
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
BIO_printf(bio_err,"issuer= %s\n",buf);
break;
case X509_V_ERR_CERT_NOT_YET_VALID:
case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
BIO_printf(bio_err,"notBefore=");
ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
BIO_printf(bio_err,"\n");
break;
case X509_V_ERR_CERT_HAS_EXPIRED:
case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
BIO_printf(bio_err,"notAfter=");
ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
BIO_printf(bio_err,"\n");
break;
}
BIO_printf(bio_err,"verify return:%d\n",ok);
return(ok);
} | /* should be X509 * but we can just have them as char *. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/pkcs7/verify.c#L215-L263 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | ssleay_rand_pseudo_bytes | static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num)
{
int ret;
unsigned long err;
ret = RAND_bytes(buf, num);
if (ret == 0)
{
err = ERR_peek_error();
if (ERR_GET_LIB(err) == ERR_LIB_RAND &&
ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED)
ERR_clear_error();
}
return (ret);
} | /* pseudo-random bytes that are guaranteed to be unique but not
unpredictable */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rand/md_rand.c#L531-L545 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RAND_poll | int RAND_poll(void)
{
unsigned long l;
unsigned long tsc;
int i;
/* There are several options to gather miscellaneous data
* but for now we will loop checking the time stamp counter (rdtsc) and
* the SuperHighResolutionTimer. Each iteration will collect 8 bytes
* of data but it is treated as only 1 byte of entropy. The call to
* ThreadSwitchWithDelay() will introduce additional variability into
* the data returned by rdtsc.
*
* Applications can agument the seed material by adding additional
* stuff with RAND_add() and should probably do so.
*/
l = GetProcessSwitchCount();
RAND_add(&l,sizeof(l),1);
/* need to cast the void* to unsigned long here */
l = (unsigned long)RunningProcess;
RAND_add(&l,sizeof(l),1);
for( i=2; i<ENTROPY_NEEDED; i++)
{
#ifdef __MWERKS__
asm
{
rdtsc
mov tsc, eax
}
#elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
asm volatile("rdtsc":"=a"(tsc)::"edx");
#endif
RAND_add(&tsc, sizeof(tsc), 1);
l = GetSuperHighResolutionTimer();
RAND_add(&l, sizeof(l), 0);
# if defined(NETWARE_LIBC)
NXThreadYield();
# else /* NETWARE_CLIB */
ThreadSwitchWithDelay();
# endif
}
return 1;
} | /* the FAQ indicates we need to provide at least 20 bytes (160 bits) of seed
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rand/rand_nw.c#L132-L180 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RAND_poll | int RAND_poll(void)
{
unsigned long l;
pid_t curr_pid = getpid();
#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
unsigned char tmpbuf[ENTROPY_NEEDED];
int n = 0;
#endif
#ifdef DEVRANDOM
static const char *randomfiles[] = { DEVRANDOM };
struct stat randomstats[sizeof(randomfiles)/sizeof(randomfiles[0])];
int fd;
unsigned int i;
#endif
#ifdef DEVRANDOM_EGD
static const char *egdsockets[] = { DEVRANDOM_EGD, NULL };
const char **egdsocket = NULL;
#endif
#ifdef DEVRANDOM
memset(randomstats,0,sizeof(randomstats));
/* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
* have this. Use /dev/urandom if you can as /dev/random may block
* if it runs out of random entries. */
for (i = 0; (i < sizeof(randomfiles)/sizeof(randomfiles[0])) &&
(n < ENTROPY_NEEDED); i++)
{
if ((fd = open(randomfiles[i], O_RDONLY
#ifdef O_NONBLOCK
|O_NONBLOCK
#endif
#ifdef O_BINARY
|O_BINARY
#endif
#ifdef O_NOCTTY /* If it happens to be a TTY (god forbid), do not make it
our controlling tty */
|O_NOCTTY
#endif
)) >= 0)
{
int usec = 10*1000; /* spend 10ms on each file */
int r;
unsigned int j;
struct stat *st=&randomstats[i];
/* Avoid using same input... Used to be O_NOFOLLOW
* above, but it's not universally appropriate... */
if (fstat(fd,st) != 0) { close(fd); continue; }
for (j=0;j<i;j++)
{
if (randomstats[j].st_ino==st->st_ino &&
randomstats[j].st_dev==st->st_dev)
break;
}
if (j<i) { close(fd); continue; }
do
{
int try_read = 0;
#if defined(OPENSSL_SYS_BEOS_R5)
/* select() is broken in BeOS R5, so we simply
* try to read something and snooze if we couldn't */
try_read = 1;
#elif defined(OPENSSL_SYS_LINUX)
/* use poll() */
struct pollfd pset;
pset.fd = fd;
pset.events = POLLIN;
pset.revents = 0;
if (poll(&pset, 1, usec / 1000) < 0)
usec = 0;
else
try_read = (pset.revents & POLLIN) != 0;
#else
/* use select() */
fd_set fset;
struct timeval t;
t.tv_sec = 0;
t.tv_usec = usec;
if (FD_SETSIZE > 0 && (unsigned)fd >= FD_SETSIZE)
{
/* can't use select, so just try to read once anyway */
try_read = 1;
}
else
{
FD_ZERO(&fset);
FD_SET(fd, &fset);
if (select(fd+1,&fset,NULL,NULL,&t) >= 0)
{
usec = t.tv_usec;
if (FD_ISSET(fd, &fset))
try_read = 1;
}
else
usec = 0;
}
#endif
if (try_read)
{
r = read(fd,(unsigned char *)tmpbuf+n, ENTROPY_NEEDED-n);
if (r > 0)
n += r;
#if defined(OPENSSL_SYS_BEOS_R5)
if (r == 0)
snooze(t.tv_usec);
#endif
}
else
r = -1;
/* Some Unixen will update t in select(), some
won't. For those who won't, or if we
didn't use select() in the first place,
give up here, otherwise, we will do
this once again for the remaining
time. */
if (usec == 10*1000)
usec = 0;
}
while ((r > 0 ||
(errno == EINTR || errno == EAGAIN)) && usec != 0 && n < ENTROPY_NEEDED);
close(fd);
}
}
#endif /* defined(DEVRANDOM) */
#ifdef DEVRANDOM_EGD
/* Use an EGD socket to read entropy from an EGD or PRNGD entropy
* collecting daemon. */
for (egdsocket = egdsockets; *egdsocket && n < ENTROPY_NEEDED; egdsocket++)
{
int r;
r = RAND_query_egd_bytes(*egdsocket, (unsigned char *)tmpbuf+n,
ENTROPY_NEEDED-n);
if (r > 0)
n += r;
}
#endif /* defined(DEVRANDOM_EGD) */
#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
if (n > 0)
{
RAND_add(tmpbuf,sizeof tmpbuf,(double)n);
OPENSSL_cleanse(tmpbuf,n);
}
#endif
/* put in some default random data, we need more than just this */
l=curr_pid;
RAND_add(&l,sizeof(l),0.0);
l=getuid();
RAND_add(&l,sizeof(l),0.0);
l=time(NULL);
RAND_add(&l,sizeof(l),0.0);
#if defined(OPENSSL_SYS_BEOS)
{
system_info sysInfo;
get_system_info(&sysInfo);
RAND_add(&sysInfo,sizeof(sysInfo),0);
}
#endif
#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
return 1;
#else
return 0;
#endif
} | /* !defined(__OpenBSD__) */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rand/rand_unix.c#L197-L380 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RAND_poll | int RAND_poll(void)
{
MEMORYSTATUS m;
HCRYPTPROV hProvider = 0;
DWORD w;
int good = 0;
/* Determine the OS version we are on so we can turn off things
* that do not work properly.
*/
OSVERSIONINFO osverinfo ;
osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
GetVersionEx( &osverinfo ) ;
#if defined(OPENSSL_SYS_WINCE)
# if defined(_WIN32_WCE) && _WIN32_WCE>=300
/* Even though MSDN says _WIN32_WCE>=210, it doesn't seem to be available
* in commonly available implementations prior 300... */
{
BYTE buf[64];
/* poll the CryptoAPI PRNG */
/* The CryptoAPI returns sizeof(buf) bytes of randomness */
if (CryptAcquireContextW(&hProvider, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT))
{
if (CryptGenRandom(hProvider, sizeof(buf), buf))
RAND_add(buf, sizeof(buf), sizeof(buf));
CryptReleaseContext(hProvider, 0);
}
}
# endif
#else /* OPENSSL_SYS_WINCE */
/*
* None of below libraries are present on Windows CE, which is
* why we #ifndef the whole section. This also excuses us from
* handling the GetProcAddress issue. The trouble is that in
* real Win32 API GetProcAddress is available in ANSI flavor
* only. In WinCE on the other hand GetProcAddress is a macro
* most commonly defined as GetProcAddressW, which accepts
* Unicode argument. If we were to call GetProcAddress under
* WinCE, I'd recommend to either redefine GetProcAddress as
* GetProcAddressA (there seem to be one in common CE spec) or
* implement own shim routine, which would accept ANSI argument
* and expand it to Unicode.
*/
{
/* load functions dynamically - not available on all systems */
HMODULE advapi = LoadLibrary(TEXT("ADVAPI32.DLL"));
HMODULE kernel = LoadLibrary(TEXT("KERNEL32.DLL"));
HMODULE user = NULL;
HMODULE netapi = LoadLibrary(TEXT("NETAPI32.DLL"));
CRYPTACQUIRECONTEXTW acquire = NULL;
CRYPTGENRANDOM gen = NULL;
CRYPTRELEASECONTEXT release = NULL;
NETSTATGET netstatget = NULL;
NETFREE netfree = NULL;
BYTE buf[64];
if (netapi)
{
netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet");
netfree = (NETFREE) GetProcAddress(netapi,"NetApiBufferFree");
}
if (netstatget && netfree)
{
LPBYTE outbuf;
/* NetStatisticsGet() is a Unicode only function
* STAT_WORKSTATION_0 contains 45 fields and STAT_SERVER_0
* contains 17 fields. We treat each field as a source of
* one byte of entropy.
*/
if (netstatget(NULL, L"LanmanWorkstation", 0, 0, &outbuf) == 0)
{
RAND_add(outbuf, sizeof(STAT_WORKSTATION_0), 45);
netfree(outbuf);
}
if (netstatget(NULL, L"LanmanServer", 0, 0, &outbuf) == 0)
{
RAND_add(outbuf, sizeof(STAT_SERVER_0), 17);
netfree(outbuf);
}
}
if (netapi)
FreeLibrary(netapi);
/* It appears like this can cause an exception deep within ADVAPI32.DLL
* at random times on Windows 2000. Reported by Jeffrey Altman.
* Only use it on NT.
*/
/* Wolfgang Marczy <WMarczy@topcall.co.at> reports that
* the RegQueryValueEx call below can hang on NT4.0 (SP6).
* So we don't use this at all for now. */
#if 0
if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
osverinfo.dwMajorVersion < 5)
{
/* Read Performance Statistics from NT/2000 registry
* The size of the performance data can vary from call
* to call so we must guess the size of the buffer to use
* and increase its size if we get an ERROR_MORE_DATA
* return instead of ERROR_SUCCESS.
*/
LONG rc=ERROR_MORE_DATA;
char * buf=NULL;
DWORD bufsz=0;
DWORD length;
while (rc == ERROR_MORE_DATA)
{
buf = realloc(buf,bufsz+8192);
if (!buf)
break;
bufsz += 8192;
length = bufsz;
rc = RegQueryValueEx(HKEY_PERFORMANCE_DATA, TEXT("Global"),
NULL, NULL, buf, &length);
}
if (rc == ERROR_SUCCESS)
{
/* For entropy count assume only least significant
* byte of each DWORD is random.
*/
RAND_add(&length, sizeof(length), 0);
RAND_add(buf, length, length / 4.0);
/* Close the Registry Key to allow Windows to cleanup/close
* the open handle
* Note: The 'HKEY_PERFORMANCE_DATA' key is implicitly opened
* when the RegQueryValueEx above is done. However, if
* it is not explicitly closed, it can cause disk
* partition manipulation problems.
*/
RegCloseKey(HKEY_PERFORMANCE_DATA);
}
if (buf)
free(buf);
}
#endif
if (advapi)
{
/*
* If it's available, then it's available in both ANSI
* and UNICODE flavors even in Win9x, documentation says.
* We favor Unicode...
*/
acquire = (CRYPTACQUIRECONTEXTW) GetProcAddress(advapi,
"CryptAcquireContextW");
gen = (CRYPTGENRANDOM) GetProcAddress(advapi,
"CryptGenRandom");
release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi,
"CryptReleaseContext");
}
if (acquire && gen && release)
{
/* poll the CryptoAPI PRNG */
/* The CryptoAPI returns sizeof(buf) bytes of randomness */
if (acquire(&hProvider, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT))
{
if (gen(hProvider, sizeof(buf), buf) != 0)
{
RAND_add(buf, sizeof(buf), 0);
good = 1;
#if 0
printf("randomness from PROV_RSA_FULL\n");
#endif
}
release(hProvider, 0);
}
/* poll the Pentium PRG with CryptoAPI */
if (acquire(&hProvider, 0, INTEL_DEF_PROV, PROV_INTEL_SEC, 0))
{
if (gen(hProvider, sizeof(buf), buf) != 0)
{
RAND_add(buf, sizeof(buf), sizeof(buf));
good = 1;
#if 0
printf("randomness from PROV_INTEL_SEC\n");
#endif
}
release(hProvider, 0);
}
}
if (advapi)
FreeLibrary(advapi);
if ((osverinfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
!OPENSSL_isservice()) &&
(user = LoadLibrary(TEXT("USER32.DLL"))))
{
GETCURSORINFO cursor;
GETFOREGROUNDWINDOW win;
GETQUEUESTATUS queue;
win = (GETFOREGROUNDWINDOW) GetProcAddress(user, "GetForegroundWindow");
cursor = (GETCURSORINFO) GetProcAddress(user, "GetCursorInfo");
queue = (GETQUEUESTATUS) GetProcAddress(user, "GetQueueStatus");
if (win)
{
/* window handle */
HWND h = win();
RAND_add(&h, sizeof(h), 0);
}
if (cursor)
{
/* unfortunately, its not safe to call GetCursorInfo()
* on NT4 even though it exists in SP3 (or SP6) and
* higher.
*/
if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
osverinfo.dwMajorVersion < 5)
cursor = 0;
}
if (cursor)
{
/* cursor position */
/* assume 2 bytes of entropy */
CURSORINFO ci;
ci.cbSize = sizeof(CURSORINFO);
if (cursor(&ci))
RAND_add(&ci, ci.cbSize, 2);
}
if (queue)
{
/* message queue status */
/* assume 1 byte of entropy */
w = queue(QS_ALLEVENTS);
RAND_add(&w, sizeof(w), 1);
}
FreeLibrary(user);
}
/* Toolhelp32 snapshot: enumerate processes, threads, modules and heap
* http://msdn.microsoft.com/library/psdk/winbase/toolhelp_5pfd.htm
* (Win 9x and 2000 only, not available on NT)
*
* This seeding method was proposed in Peter Gutmann, Software
* Generation of Practically Strong Random Numbers,
* http://www.usenix.org/publications/library/proceedings/sec98/gutmann.html
* revised version at http://www.cryptoengines.com/~peter/06_random.pdf
* (The assignment of entropy estimates below is arbitrary, but based
* on Peter's analysis the full poll appears to be safe. Additional
* interactive seeding is encouraged.)
*/
if (kernel)
{
CREATETOOLHELP32SNAPSHOT snap;
CLOSETOOLHELP32SNAPSHOT close_snap;
HANDLE handle;
HEAP32FIRST heap_first;
HEAP32NEXT heap_next;
HEAP32LIST heaplist_first, heaplist_next;
PROCESS32 process_first, process_next;
THREAD32 thread_first, thread_next;
MODULE32 module_first, module_next;
HEAPLIST32 hlist;
HEAPENTRY32 hentry;
PROCESSENTRY32 p;
THREADENTRY32 t;
MODULEENTRY32 m;
DWORD starttime = 0;
snap = (CREATETOOLHELP32SNAPSHOT)
GetProcAddress(kernel, "CreateToolhelp32Snapshot");
close_snap = (CLOSETOOLHELP32SNAPSHOT)
GetProcAddress(kernel, "CloseToolhelp32Snapshot");
heap_first = (HEAP32FIRST) GetProcAddress(kernel, "Heap32First");
heap_next = (HEAP32NEXT) GetProcAddress(kernel, "Heap32Next");
heaplist_first = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListFirst");
heaplist_next = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListNext");
process_first = (PROCESS32) GetProcAddress(kernel, "Process32First");
process_next = (PROCESS32) GetProcAddress(kernel, "Process32Next");
thread_first = (THREAD32) GetProcAddress(kernel, "Thread32First");
thread_next = (THREAD32) GetProcAddress(kernel, "Thread32Next");
module_first = (MODULE32) GetProcAddress(kernel, "Module32First");
module_next = (MODULE32) GetProcAddress(kernel, "Module32Next");
if (snap && heap_first && heap_next && heaplist_first &&
heaplist_next && process_first && process_next &&
thread_first && thread_next && module_first &&
module_next && (handle = snap(TH32CS_SNAPALL,0))
!= INVALID_HANDLE_VALUE)
{
/* heap list and heap walking */
/* HEAPLIST32 contains 3 fields that will change with
* each entry. Consider each field a source of 1 byte
* of entropy.
* HEAPENTRY32 contains 5 fields that will change with
* each entry. Consider each field a source of 1 byte
* of entropy.
*/
ZeroMemory(&hlist, sizeof(HEAPLIST32));
hlist.dwSize = sizeof(HEAPLIST32);
if (good) starttime = GetTickCount();
#ifdef _MSC_VER
if (heaplist_first(handle, &hlist))
{
/*
following discussion on dev ML, exception on WinCE (or other Win
platform) is theoretically of unknown origin; prevent infinite
loop here when this theoretical case occurs; otherwise cope with
the expected (MSDN documented) exception-throwing behaviour of
Heap32Next() on WinCE.
based on patch in original message by Tanguy Fautré (2009/03/02)
Subject: RAND_poll() and CreateToolhelp32Snapshot() stability
*/
int ex_cnt_limit = 42;
do
{
RAND_add(&hlist, hlist.dwSize, 3);
__try
{
ZeroMemory(&hentry, sizeof(HEAPENTRY32));
hentry.dwSize = sizeof(HEAPENTRY32);
if (heap_first(&hentry,
hlist.th32ProcessID,
hlist.th32HeapID))
{
int entrycnt = 80;
do
RAND_add(&hentry,
hentry.dwSize, 5);
while (heap_next(&hentry)
&& (!good || (GetTickCount()-starttime)<MAXDELAY)
&& --entrycnt > 0);
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
/* ignore access violations when walking the heap list */
ex_cnt_limit--;
}
} while (heaplist_next(handle, &hlist)
&& (!good || (GetTickCount()-starttime)<MAXDELAY)
&& ex_cnt_limit > 0);
}
#else
if (heaplist_first(handle, &hlist))
{
do
{
RAND_add(&hlist, hlist.dwSize, 3);
hentry.dwSize = sizeof(HEAPENTRY32);
if (heap_first(&hentry,
hlist.th32ProcessID,
hlist.th32HeapID))
{
int entrycnt = 80;
do
RAND_add(&hentry,
hentry.dwSize, 5);
while (heap_next(&hentry)
&& --entrycnt > 0);
}
} while (heaplist_next(handle, &hlist)
&& (!good || (GetTickCount()-starttime)<MAXDELAY));
}
#endif
/* process walking */
/* PROCESSENTRY32 contains 9 fields that will change
* with each entry. Consider each field a source of
* 1 byte of entropy.
*/
p.dwSize = sizeof(PROCESSENTRY32);
if (good) starttime = GetTickCount();
if (process_first(handle, &p))
do
RAND_add(&p, p.dwSize, 9);
while (process_next(handle, &p) && (!good || (GetTickCount()-starttime)<MAXDELAY));
/* thread walking */
/* THREADENTRY32 contains 6 fields that will change
* with each entry. Consider each field a source of
* 1 byte of entropy.
*/
t.dwSize = sizeof(THREADENTRY32);
if (good) starttime = GetTickCount();
if (thread_first(handle, &t))
do
RAND_add(&t, t.dwSize, 6);
while (thread_next(handle, &t) && (!good || (GetTickCount()-starttime)<MAXDELAY));
/* module walking */
/* MODULEENTRY32 contains 9 fields that will change
* with each entry. Consider each field a source of
* 1 byte of entropy.
*/
m.dwSize = sizeof(MODULEENTRY32);
if (good) starttime = GetTickCount();
if (module_first(handle, &m))
do
RAND_add(&m, m.dwSize, 9);
while (module_next(handle, &m)
&& (!good || (GetTickCount()-starttime)<MAXDELAY));
if (close_snap)
close_snap(handle);
else
CloseHandle(handle);
}
FreeLibrary(kernel);
}
}
#endif /* !OPENSSL_SYS_WINCE */
/* timer data */
readtimer();
/* memory usage statistics */
GlobalMemoryStatus(&m);
RAND_add(&m, sizeof(m), 1);
/* process ID */
w = GetCurrentProcessId();
RAND_add(&w, sizeof(w), 1);
#if 0
printf("Exiting RAND_poll\n");
#endif
return(1);
} | /* !OPENSSL_SYS_WINCE */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rand/rand_win.c#L192-L632 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | readtimer | static void readtimer(void)
{
DWORD w;
LARGE_INTEGER l;
static int have_perfc = 1;
#if defined(_MSC_VER) && defined(_M_X86)
static int have_tsc = 1;
DWORD cyclecount;
if (have_tsc) {
__try {
__asm {
_emit 0x0f
_emit 0x31
mov cyclecount, eax
}
RAND_add(&cyclecount, sizeof(cyclecount), 1);
} __except(EXCEPTION_EXECUTE_HANDLER) {
have_tsc = 0;
}
}
#else
# define have_tsc 0
#endif
if (have_perfc) {
if (QueryPerformanceCounter(&l) == 0)
have_perfc = 0;
else
RAND_add(&l, sizeof(l), 0);
}
if (!have_tsc && !have_perfc) {
w = GetTickCount();
RAND_add(&w, sizeof(w), 0);
}
} | /* feed timing information to the PRNG */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rand/rand_win.c#L682-L718 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | readscreen | static void readscreen(void)
{
#if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN)
HDC hScrDC; /* screen DC */
HDC hMemDC; /* memory DC */
HBITMAP hBitmap; /* handle for our bitmap */
HBITMAP hOldBitmap; /* handle for previous bitmap */
BITMAP bm; /* bitmap properties */
unsigned int size; /* size of bitmap */
char *bmbits; /* contents of bitmap */
int w; /* screen width */
int h; /* screen height */
int y; /* y-coordinate of screen lines to grab */
int n = 16; /* number of screen lines to grab at a time */
if (GetVersion() < 0x80000000 && OPENSSL_isservice()>0)
return;
/* Create a screen DC and a memory DC compatible to screen DC */
hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
hMemDC = CreateCompatibleDC(hScrDC);
/* Get screen resolution */
w = GetDeviceCaps(hScrDC, HORZRES);
h = GetDeviceCaps(hScrDC, VERTRES);
/* Create a bitmap compatible with the screen DC */
hBitmap = CreateCompatibleBitmap(hScrDC, w, n);
/* Select new bitmap into memory DC */
hOldBitmap = SelectObject(hMemDC, hBitmap);
/* Get bitmap properties */
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
bmbits = OPENSSL_malloc(size);
if (bmbits) {
/* Now go through the whole screen, repeatedly grabbing n lines */
for (y = 0; y < h-n; y += n)
{
unsigned char md[MD_DIGEST_LENGTH];
/* Bitblt screen DC to memory DC */
BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY);
/* Copy bitmap bits from memory DC to bmbits */
GetBitmapBits(hBitmap, size, bmbits);
/* Get the hash of the bitmap */
MD(bmbits,size,md);
/* Seed the random generator with the hash value */
RAND_add(md, MD_DIGEST_LENGTH, 0);
}
OPENSSL_free(bmbits);
}
/* Select old bitmap back into memory DC */
hBitmap = SelectObject(hMemDC, hOldBitmap);
/* Clean up */
DeleteObject(hBitmap);
DeleteDC(hMemDC);
DeleteDC(hScrDC);
#endif /* !OPENSSL_SYS_WINCE */
} | /* feed screen contents to PRNG */
/*****************************************************************************
*
* Created 960901 by Gertjan van Oosten, gertjan@West.NL, West Consulting B.V.
*
* Code adapted from
* <URL:http://support.microsoft.com/default.aspx?scid=kb;[LN];97193>;
* the original copyright message is:
*
* (C) Copyright Microsoft Corp. 1993. All rights reserved.
*
* You have a royalty-free right to use, modify, reproduce and
* distribute the Sample Files (and/or any modified version) in
* any way you find useful, provided that you agree that
* Microsoft has no warranty obligations or liability for any
* Sample Application Files which are modified.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rand/rand_win.c#L738-L805 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RAND_load_file | int RAND_load_file(const char *file, long bytes)
{
/* If bytes >= 0, read up to 'bytes' bytes.
* if bytes == -1, read complete file. */
MS_STATIC unsigned char buf[BUFSIZE];
#ifndef OPENSSL_NO_POSIX_IO
struct stat sb;
#endif
int i,ret=0,n;
FILE *in;
if (file == NULL) return(0);
#ifndef OPENSSL_NO_POSIX_IO
#ifdef PURIFY
/* struct stat can have padding and unused fields that may not be
* initialized in the call to stat(). We need to clear the entire
* structure before calling RAND_add() to avoid complaints from
* applications such as Valgrind.
*/
memset(&sb, 0, sizeof(sb));
#endif
if (stat(file,&sb) < 0) return(0);
RAND_add(&sb,sizeof(sb),0.0);
#endif
if (bytes == 0) return(ret);
#ifdef OPENSSL_SYS_VMS
in=vms_fopen(file,"rb",VMS_OPEN_ATTRS);
#else
in=fopen(file,"rb");
#endif
if (in == NULL) goto err;
#if defined(S_IFBLK) && defined(S_IFCHR) && !defined(OPNESSL_NO_POSIX_IO)
if (sb.st_mode & (S_IFBLK | S_IFCHR)) {
/* this file is a device. we don't want read an infinite number
* of bytes from a random device, nor do we want to use buffered
* I/O because we will waste system entropy.
*/
bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */
setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */
}
#endif
for (;;)
{
if (bytes > 0)
n = (bytes < BUFSIZE)?(int)bytes:BUFSIZE;
else
n = BUFSIZE;
i=fread(buf,1,n,in);
if (i <= 0) break;
#ifdef PURIFY
RAND_add(buf,i,(double)i);
#else
/* even if n != i, use the full array */
RAND_add(buf,n,(double)i);
#endif
ret+=i;
if (bytes > 0)
{
bytes-=n;
if (bytes <= 0) break;
}
}
fclose(in);
OPENSSL_cleanse(buf,BUFSIZE);
err:
return(ret);
} | /* #define RFILE ".rnd" - defined in ../../e_os.h */
/* Note that these functions are intended for seed files only.
* Entropy devices and EGD sockets are handled in rand_unix.c */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rand/randfile.c#L106-L175 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | main | int main(int argc,char **argv)
{
unsigned char buf[2500];
int i,j,k,s,sign,nsign,err=0;
unsigned long n1;
unsigned long n2[16];
unsigned long runs[2][34];
/*double d; */
long d;
i = RAND_pseudo_bytes(buf,2500);
if (i < 0)
{
printf ("init failed, the rand method is not properly installed\n");
err++;
goto err;
}
n1=0;
for (i=0; i<16; i++) n2[i]=0;
for (i=0; i<34; i++) runs[0][i]=runs[1][i]=0;
/* test 1 and 2 */
sign=0;
nsign=0;
for (i=0; i<2500; i++)
{
j=buf[i];
n2[j&0x0f]++;
n2[(j>>4)&0x0f]++;
for (k=0; k<8; k++)
{
s=(j&0x01);
if (s == sign)
nsign++;
else
{
if (nsign > 34) nsign=34;
if (nsign != 0)
{
runs[sign][nsign-1]++;
if (nsign > 6)
runs[sign][5]++;
}
sign=s;
nsign=1;
}
if (s) n1++;
j>>=1;
}
}
if (nsign > 34) nsign=34;
if (nsign != 0) runs[sign][nsign-1]++;
/* test 1 */
if (!((9654 < n1) && (n1 < 10346)))
{
printf("test 1 failed, X=%lu\n",n1);
err++;
}
printf("test 1 done\n");
/* test 2 */
#ifdef undef
d=0;
for (i=0; i<16; i++)
d+=n2[i]*n2[i];
d=d*16.0/5000.0-5000.0;
if (!((1.03 < d) && (d < 57.4)))
{
printf("test 2 failed, X=%.2f\n",d);
err++;
}
#endif
d=0;
for (i=0; i<16; i++)
d+=n2[i]*n2[i];
d=(d*8)/25-500000;
if (!((103 < d) && (d < 5740)))
{
printf("test 2 failed, X=%ld.%02ld\n",d/100L,d%100L);
err++;
}
printf("test 2 done\n");
/* test 3 */
for (i=0; i<2; i++)
{
if (!((2267 < runs[i][0]) && (runs[i][0] < 2733)))
{
printf("test 3 failed, bit=%d run=%d num=%lu\n",
i,1,runs[i][0]);
err++;
}
if (!((1079 < runs[i][1]) && (runs[i][1] < 1421)))
{
printf("test 3 failed, bit=%d run=%d num=%lu\n",
i,2,runs[i][1]);
err++;
}
if (!(( 502 < runs[i][2]) && (runs[i][2] < 748)))
{
printf("test 3 failed, bit=%d run=%d num=%lu\n",
i,3,runs[i][2]);
err++;
}
if (!(( 223 < runs[i][3]) && (runs[i][3] < 402)))
{
printf("test 3 failed, bit=%d run=%d num=%lu\n",
i,4,runs[i][3]);
err++;
}
if (!(( 90 < runs[i][4]) && (runs[i][4] < 223)))
{
printf("test 3 failed, bit=%d run=%d num=%lu\n",
i,5,runs[i][4]);
err++;
}
if (!(( 90 < runs[i][5]) && (runs[i][5] < 223)))
{
printf("test 3 failed, bit=%d run=%d num=%lu\n",
i,6,runs[i][5]);
err++;
}
}
printf("test 3 done\n");
/* test 4 */
if (runs[0][33] != 0)
{
printf("test 4 failed, bit=%d run=%d num=%lu\n",
0,34,runs[0][33]);
err++;
}
if (runs[1][33] != 0)
{
printf("test 4 failed, bit=%d run=%d num=%lu\n",
1,34,runs[1][33]);
err++;
}
printf("test 4 done\n");
err:
err=((err)?1:0);
#ifdef OPENSSL_SYS_NETWARE
if (err) printf("ERROR: %d\n", err);
#endif
EXIT(err);
return(err);
} | /* some FIPS 140-1 random number test */
/* some simple tests */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rand/randtest.c#L68-L219 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RC2_ecb_encrypt | void RC2_ecb_encrypt(const unsigned char *in, unsigned char *out, RC2_KEY *ks,
int encrypt)
{
unsigned long l,d[2];
c2l(in,l); d[0]=l;
c2l(in,l); d[1]=l;
if (encrypt)
RC2_encrypt(d,ks);
else
RC2_decrypt(d,ks);
l=d[0]; l2c(l,out);
l=d[1]; l2c(l,out);
l=d[0]=d[1]=0;
} | /* RC2 as implemented frm a posting from
* Newsgroups: sci.crypt
* Sender: pgut01@cs.auckland.ac.nz (Peter Gutmann)
* Subject: Specification for Ron Rivests Cipher No.2
* Message-ID: <4fk39f$f70@net.auckland.ac.nz>
* Date: 11 Feb 1996 06:45:03 GMT
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rc2/rc2_ecb.c#L73-L87 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RC2_set_key | void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
{
int i,j;
unsigned char *k;
RC2_INT *ki;
unsigned int c,d;
k= (unsigned char *)&(key->data[0]);
*k=0; /* for if there is a zero length key */
if (len > 128) len=128;
if (bits <= 0) bits=1024;
if (bits > 1024) bits=1024;
for (i=0; i<len; i++)
k[i]=data[i];
/* expand table */
d=k[len-1];
j=0;
for (i=len; i < 128; i++,j++)
{
d=key_table[(k[j]+d)&0xff];
k[i]=d;
}
/* hmm.... key reduction to 'bits' bits */
j=(bits+7)>>3;
i=128-j;
c= (0xff>>(-bits & 0x07));
d=key_table[k[i]&c];
k[i]=d;
while (i--)
{
d=key_table[k[i+j]^d];
k[i]=d;
}
/* copy from bytes into RC2_INT's */
ki= &(key->data[63]);
for (i=127; i>=0; i-=2)
*(ki--)=((k[i]<<8)|k[i-1])&0xffff;
} | /* It has come to my attention that there are 2 versions of the RC2
* key schedule. One which is normal, and anther which has a hook to
* use a reduced key length.
* BSAFE uses the 'retarded' version. What I previously shipped is
* the same as specifying 1024 for the 'bits' parameter. Bsafe uses
* a version where the bits parameter is the same as len*8 */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rc2/rc2_skey.c#L97-L141 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RC2_cfb64_encrypt | void RC2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
long length, RC2_KEY *schedule, unsigned char *ivec,
int *num, int encrypt)
{
register unsigned long v0,v1,t;
register int n= *num;
register long l=length;
unsigned long ti[2];
unsigned char *iv,c,cc;
iv=(unsigned char *)ivec;
if (encrypt)
{
while (l--)
{
if (n == 0)
{
c2l(iv,v0); ti[0]=v0;
c2l(iv,v1); ti[1]=v1;
RC2_encrypt((unsigned long *)ti,schedule);
iv=(unsigned char *)ivec;
t=ti[0]; l2c(t,iv);
t=ti[1]; l2c(t,iv);
iv=(unsigned char *)ivec;
}
c= *(in++)^iv[n];
*(out++)=c;
iv[n]=c;
n=(n+1)&0x07;
}
}
else
{
while (l--)
{
if (n == 0)
{
c2l(iv,v0); ti[0]=v0;
c2l(iv,v1); ti[1]=v1;
RC2_encrypt((unsigned long *)ti,schedule);
iv=(unsigned char *)ivec;
t=ti[0]; l2c(t,iv);
t=ti[1]; l2c(t,iv);
iv=(unsigned char *)ivec;
}
cc= *(in++);
c=iv[n];
iv[n]=cc;
*(out++)=c^cc;
n=(n+1)&0x07;
}
}
v0=v1=ti[0]=ti[1]=t=c=cc=0;
*num=n;
} | /* The input and output encrypted as though 64bit cfb mode is being
* used. The extra state information to record how much of the
* 64bit block we have used is contained in *num;
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rc2/rc2cfb64.c#L67-L121 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RC2_ofb64_encrypt | void RC2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
long length, RC2_KEY *schedule, unsigned char *ivec,
int *num)
{
register unsigned long v0,v1,t;
register int n= *num;
register long l=length;
unsigned char d[8];
register char *dp;
unsigned long ti[2];
unsigned char *iv;
int save=0;
iv=(unsigned char *)ivec;
c2l(iv,v0);
c2l(iv,v1);
ti[0]=v0;
ti[1]=v1;
dp=(char *)d;
l2c(v0,dp);
l2c(v1,dp);
while (l--)
{
if (n == 0)
{
RC2_encrypt((unsigned long *)ti,schedule);
dp=(char *)d;
t=ti[0]; l2c(t,dp);
t=ti[1]; l2c(t,dp);
save++;
}
*(out++)= *(in++)^d[n];
n=(n+1)&0x07;
}
if (save)
{
v0=ti[0];
v1=ti[1];
iv=(unsigned char *)ivec;
l2c(v0,iv);
l2c(v1,iv);
}
t=v0=v1=ti[0]=ti[1]=0;
*num=n;
} | /* The input and output encrypted as though 64bit ofb mode is being
* used. The extra state information to record how much of the
* 64bit block we have used is contained in *num;
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rc2/rc2ofb64.c#L66-L110 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RC4 | void RC4(RC4_KEY *key, size_t len, const unsigned char *indata,
unsigned char *outdata)
{
register RC4_INT *d;
register RC4_INT x,y,tx,ty;
size_t i;
x=key->x;
y=key->y;
d=key->data;
#if defined(RC4_CHUNK)
/*
* The original reason for implementing this(*) was the fact that
* pre-21164a Alpha CPUs don't have byte load/store instructions
* and e.g. a byte store has to be done with 64-bit load, shift,
* and, or and finally 64-bit store. Peaking data and operating
* at natural word size made it possible to reduce amount of
* instructions as well as to perform early read-ahead without
* suffering from RAW (read-after-write) hazard. This resulted
* in ~40%(**) performance improvement on 21064 box with gcc.
* But it's not only Alpha users who win here:-) Thanks to the
* early-n-wide read-ahead this implementation also exhibits
* >40% speed-up on SPARC and 20-30% on 64-bit MIPS (depending
* on sizeof(RC4_INT)).
*
* (*) "this" means code which recognizes the case when input
* and output pointers appear to be aligned at natural CPU
* word boundary
* (**) i.e. according to 'apps/openssl speed rc4' benchmark,
* crypto/rc4/rc4speed.c exhibits almost 70% speed-up...
*
* Cavets.
*
* - RC4_CHUNK="unsigned long long" should be a #1 choice for
* UltraSPARC. Unfortunately gcc generates very slow code
* (2.5-3 times slower than one generated by Sun's WorkShop
* C) and therefore gcc (at least 2.95 and earlier) should
* always be told that RC4_CHUNK="unsigned long".
*
* <appro@fy.chalmers.se>
*/
# define RC4_STEP ( \
x=(x+1) &0xff, \
tx=d[x], \
y=(tx+y)&0xff, \
ty=d[y], \
d[y]=tx, \
d[x]=ty, \
(RC4_CHUNK)d[(tx+ty)&0xff]\
)
if ( ( ((size_t)indata & (sizeof(RC4_CHUNK)-1)) |
((size_t)outdata & (sizeof(RC4_CHUNK)-1)) ) == 0 )
{
RC4_CHUNK ichunk,otp;
const union { long one; char little; } is_endian = {1};
/*
* I reckon we can afford to implement both endian
* cases and to decide which way to take at run-time
* because the machine code appears to be very compact
* and redundant 1-2KB is perfectly tolerable (i.e.
* in case the compiler fails to eliminate it:-). By
* suggestion from Terrel Larson <terr@terralogic.net>
* who also stands for the is_endian union:-)
*
* Special notes.
*
* - is_endian is declared automatic as doing otherwise
* (declaring static) prevents gcc from eliminating
* the redundant code;
* - compilers (those I've tried) don't seem to have
* problems eliminating either the operators guarded
* by "if (sizeof(RC4_CHUNK)==8)" or the condition
* expressions themselves so I've got 'em to replace
* corresponding #ifdefs from the previous version;
* - I chose to let the redundant switch cases when
* sizeof(RC4_CHUNK)!=8 be (were also #ifdefed
* before);
* - in case you wonder "&(sizeof(RC4_CHUNK)*8-1)" in
* [LB]ESHFT guards against "shift is out of range"
* warnings when sizeof(RC4_CHUNK)!=8
*
* <appro@fy.chalmers.se>
*/
if (!is_endian.little)
{ /* BIG-ENDIAN CASE */
# define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK))
{
ichunk = *(RC4_CHUNK *)indata;
otp = RC4_STEP<<BESHFT(0);
otp |= RC4_STEP<<BESHFT(1);
otp |= RC4_STEP<<BESHFT(2);
otp |= RC4_STEP<<BESHFT(3);
if (sizeof(RC4_CHUNK)==8)
{
otp |= RC4_STEP<<BESHFT(4);
otp |= RC4_STEP<<BESHFT(5);
otp |= RC4_STEP<<BESHFT(6);
otp |= RC4_STEP<<BESHFT(7);
}
*(RC4_CHUNK *)outdata = otp^ichunk;
indata += sizeof(RC4_CHUNK);
outdata += sizeof(RC4_CHUNK);
}
if (len)
{
RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
ichunk = *(RC4_CHUNK *)indata;
ochunk = *(RC4_CHUNK *)outdata;
otp = 0;
i = BESHFT(0);
mask <<= (sizeof(RC4_CHUNK)-len)<<3;
switch (len&(sizeof(RC4_CHUNK)-1))
{
case 7: otp = RC4_STEP<<i, i-=8;
case 6: otp |= RC4_STEP<<i, i-=8;
case 5: otp |= RC4_STEP<<i, i-=8;
case 4: otp |= RC4_STEP<<i, i-=8;
case 3: otp |= RC4_STEP<<i, i-=8;
case 2: otp |= RC4_STEP<<i, i-=8;
case 1: otp |= RC4_STEP<<i, i-=8;
case 0: ; /*
* it's never the case,
* but it has to be here
* for ultrix?
*/
}
ochunk &= ~mask;
ochunk |= (otp^ichunk) & mask;
*(RC4_CHUNK *)outdata = ochunk;
}
key->x=x;
key->y=y;
return;
}
else
{ /* LITTLE-ENDIAN CASE */
# define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1))
for (;len&(0-sizeof(RC4_CHUNK));len-=sizeof(RC4_CHUNK))
{
ichunk = *(RC4_CHUNK *)indata;
otp = RC4_STEP;
otp |= RC4_STEP<<8;
otp |= RC4_STEP<<16;
otp |= RC4_STEP<<24;
if (sizeof(RC4_CHUNK)==8)
{
otp |= RC4_STEP<<LESHFT(4);
otp |= RC4_STEP<<LESHFT(5);
otp |= RC4_STEP<<LESHFT(6);
otp |= RC4_STEP<<LESHFT(7);
}
*(RC4_CHUNK *)outdata = otp^ichunk;
indata += sizeof(RC4_CHUNK);
outdata += sizeof(RC4_CHUNK);
}
if (len)
{
RC4_CHUNK mask=(RC4_CHUNK)-1, ochunk;
ichunk = *(RC4_CHUNK *)indata;
ochunk = *(RC4_CHUNK *)outdata;
otp = 0;
i = 0;
mask >>= (sizeof(RC4_CHUNK)-len)<<3;
switch (len&(sizeof(RC4_CHUNK)-1))
{
case 7: otp = RC4_STEP, i+=8;
case 6: otp |= RC4_STEP<<i, i+=8;
case 5: otp |= RC4_STEP<<i, i+=8;
case 4: otp |= RC4_STEP<<i, i+=8;
case 3: otp |= RC4_STEP<<i, i+=8;
case 2: otp |= RC4_STEP<<i, i+=8;
case 1: otp |= RC4_STEP<<i, i+=8;
case 0: ; /*
* it's never the case,
* but it has to be here
* for ultrix?
*/
}
ochunk &= ~mask;
ochunk |= (otp^ichunk) & mask;
*(RC4_CHUNK *)outdata = ochunk;
}
key->x=x;
key->y=y;
return;
}
}
#endif
#define LOOP(in,out) \
x=((x+1)&0xff); \
tx=d[x]; \
y=(tx+y)&0xff; \
d[x]=ty=d[y]; \
d[y]=tx; \
(out) = d[(tx+ty)&0xff]^ (in);
#ifndef RC4_INDEX
#define RC4_LOOP(a,b,i) LOOP(*((a)++),*((b)++))
#else
#define RC4_LOOP(a,b,i) LOOP(a[i],b[i])
#endif
i=len>>3;
if (i)
{
for (;;)
{
RC4_LOOP(indata,outdata,0);
RC4_LOOP(indata,outdata,1);
RC4_LOOP(indata,outdata,2);
RC4_LOOP(indata,outdata,3);
RC4_LOOP(indata,outdata,4);
RC4_LOOP(indata,outdata,5);
RC4_LOOP(indata,outdata,6);
RC4_LOOP(indata,outdata,7);
#ifdef RC4_INDEX
indata+=8;
outdata+=8;
#endif
if (--i == 0) break;
}
}
i=len&0x07;
if (i)
{
for (;;)
{
RC4_LOOP(indata,outdata,0); if (--i == 0) break;
RC4_LOOP(indata,outdata,1); if (--i == 0) break;
RC4_LOOP(indata,outdata,2); if (--i == 0) break;
RC4_LOOP(indata,outdata,3); if (--i == 0) break;
RC4_LOOP(indata,outdata,4); if (--i == 0) break;
RC4_LOOP(indata,outdata,5); if (--i == 0) break;
RC4_LOOP(indata,outdata,6); if (--i == 0) break;
}
}
key->x=x;
key->y=y;
} | /* RC4 as implemented from a posting from
* Newsgroups: sci.crypt
* From: sterndark@netcom.com (David Sterndark)
* Subject: RC4 Algorithm revealed.
* Message-ID: <sternCvKL4B.Hyy@netcom.com>
* Date: Wed, 14 Sep 1994 06:35:31 GMT
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rc4/rc4_enc.c#L70-L315 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RC4_set_key | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
{
register RC4_INT tmp;
register int id1,id2;
register RC4_INT *d;
unsigned int i;
d= &(key->data[0]);
key->x = 0;
key->y = 0;
id1=id2=0;
#define SK_LOOP(d,n) { \
tmp=d[(n)]; \
id2 = (data[id1] + tmp + id2) & 0xff; \
if (++id1 == len) id1=0; \
d[(n)]=d[id2]; \
d[id2]=tmp; }
#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM)
# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
defined(__INTEL__) || \
defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64)
if (sizeof(RC4_INT) > 1) {
/*
* Unlike all other x86 [and x86_64] implementations,
* Intel P4 core [including EM64T] was found to perform
* poorly with wider RC4_INT. Performance improvement
* for IA-32 hand-coded assembler turned out to be 2.8x
* if re-coded for RC4_CHAR! It's however inappropriate
* to just switch to RC4_CHAR for x86[_64], as non-P4
* implementations suffer from significant performance
* losses then, e.g. PIII exhibits >2x deterioration,
* and so does Opteron. In order to assure optimal
* all-round performance, let us [try to] detect P4 at
* run-time by checking upon HTT bit in CPU capability
* vector and set up compressed key schedule, which is
* recognized by correspondingly updated assembler
* module...
* <appro@fy.chalmers.se>
*/
if (OPENSSL_ia32cap_P & (1<<28)) {
unsigned char *cp=(unsigned char *)d;
for (i=0;i<256;i++) cp[i]=i;
for (i=0;i<256;i++) SK_LOOP(cp,i);
/* mark schedule as compressed! */
d[256/sizeof(RC4_INT)]=-1;
return;
}
}
# endif
#endif
for (i=0; i < 256; i++) d[i]=i;
for (i=0; i < 256; i+=4)
{
SK_LOOP(d,i+0);
SK_LOOP(d,i+1);
SK_LOOP(d,i+2);
SK_LOOP(d,i+3);
}
} | /* RC4 as implemented from a posting from
* Newsgroups: sci.crypt
* From: sterndark@netcom.com (David Sterndark)
* Subject: RC4 Algorithm revealed.
* Message-ID: <sternCvKL4B.Hyy@netcom.com>
* Date: Wed, 14 Sep 1994 06:35:31 GMT
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rc4/rc4_skey.c#L88-L149 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RC5_32_cfb64_encrypt | void RC5_32_cfb64_encrypt(const unsigned char *in, unsigned char *out,
long length, RC5_32_KEY *schedule,
unsigned char *ivec, int *num, int encrypt)
{
register unsigned long v0,v1,t;
register int n= *num;
register long l=length;
unsigned long ti[2];
unsigned char *iv,c,cc;
iv=(unsigned char *)ivec;
if (encrypt)
{
while (l--)
{
if (n == 0)
{
c2l(iv,v0); ti[0]=v0;
c2l(iv,v1); ti[1]=v1;
RC5_32_encrypt((unsigned long *)ti,schedule);
iv=(unsigned char *)ivec;
t=ti[0]; l2c(t,iv);
t=ti[1]; l2c(t,iv);
iv=(unsigned char *)ivec;
}
c= *(in++)^iv[n];
*(out++)=c;
iv[n]=c;
n=(n+1)&0x07;
}
}
else
{
while (l--)
{
if (n == 0)
{
c2l(iv,v0); ti[0]=v0;
c2l(iv,v1); ti[1]=v1;
RC5_32_encrypt((unsigned long *)ti,schedule);
iv=(unsigned char *)ivec;
t=ti[0]; l2c(t,iv);
t=ti[1]; l2c(t,iv);
iv=(unsigned char *)ivec;
}
cc= *(in++);
c=iv[n];
iv[n]=cc;
*(out++)=c^cc;
n=(n+1)&0x07;
}
}
v0=v1=ti[0]=ti[1]=t=c=cc=0;
*num=n;
} | /* The input and output encrypted as though 64bit cfb mode is being
* used. The extra state information to record how much of the
* 64bit block we have used is contained in *num;
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rc5/rc5cfb64.c#L67-L121 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RC5_32_ofb64_encrypt | void RC5_32_ofb64_encrypt(const unsigned char *in, unsigned char *out,
long length, RC5_32_KEY *schedule,
unsigned char *ivec, int *num)
{
register unsigned long v0,v1,t;
register int n= *num;
register long l=length;
unsigned char d[8];
register char *dp;
unsigned long ti[2];
unsigned char *iv;
int save=0;
iv=(unsigned char *)ivec;
c2l(iv,v0);
c2l(iv,v1);
ti[0]=v0;
ti[1]=v1;
dp=(char *)d;
l2c(v0,dp);
l2c(v1,dp);
while (l--)
{
if (n == 0)
{
RC5_32_encrypt((unsigned long *)ti,schedule);
dp=(char *)d;
t=ti[0]; l2c(t,dp);
t=ti[1]; l2c(t,dp);
save++;
}
*(out++)= *(in++)^d[n];
n=(n+1)&0x07;
}
if (save)
{
v0=ti[0];
v1=ti[1];
iv=(unsigned char *)ivec;
l2c(v0,iv);
l2c(v1,iv);
}
t=v0=v1=ti[0]=ti[1]=0;
*num=n;
} | /* The input and output encrypted as though 64bit ofb mode is being
* used. The extra state information to record how much of the
* 64bit block we have used is contained in *num;
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rc5/rc5ofb64.c#L66-L110 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | rsa_cb | static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
void *exarg)
{
if(operation == ASN1_OP_NEW_PRE) {
*pval = (ASN1_VALUE *)RSA_new();
if(*pval) return 2;
return 0;
} else if(operation == ASN1_OP_FREE_PRE) {
RSA_free((RSA *)*pval);
*pval = NULL;
return 2;
}
return 1;
} | /* Override the default free and new methods */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rsa/rsa_asn1.c#L66-L79 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RSA_eay_private_encrypt | static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
BIGNUM *f, *ret, *br, *res;
int i,j,k,num=0,r= -1;
unsigned char *buf=NULL;
BN_CTX *ctx=NULL;
int local_blinding = 0;
BN_BLINDING *blinding = NULL;
if ((ctx=BN_CTX_new()) == NULL) goto err;
BN_CTX_start(ctx);
f = BN_CTX_get(ctx);
br = BN_CTX_get(ctx);
ret = BN_CTX_get(ctx);
num = BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num);
if(!f || !ret || !buf)
{
RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);
goto err;
}
switch (padding)
{
case RSA_PKCS1_PADDING:
i=RSA_padding_add_PKCS1_type_1(buf,num,from,flen);
break;
case RSA_X931_PADDING:
i=RSA_padding_add_X931(buf,num,from,flen);
break;
case RSA_NO_PADDING:
i=RSA_padding_add_none(buf,num,from,flen);
break;
case RSA_SSLV23_PADDING:
default:
RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
goto err;
}
if (i <= 0) goto err;
if (BN_bin2bn(buf,num,f) == NULL) goto err;
if (BN_ucmp(f, rsa->n) >= 0)
{
/* usually the padding functions would catch this */
RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
goto err;
}
if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
{
blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
if (blinding == NULL)
{
RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR);
goto err;
}
}
if (blinding != NULL)
if (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx))
goto err;
if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
((rsa->p != NULL) &&
(rsa->q != NULL) &&
(rsa->dmp1 != NULL) &&
(rsa->dmq1 != NULL) &&
(rsa->iqmp != NULL)) )
{
if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)) goto err;
}
else
{
BIGNUM local_d;
BIGNUM *d = NULL;
if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
{
BN_init(&local_d);
d = &local_d;
BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
}
else
d= rsa->d;
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
if(!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))
goto err;
if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,
rsa->_method_mod_n)) goto err;
}
if (blinding)
if (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx))
goto err;
if (padding == RSA_X931_PADDING)
{
BN_sub(f, rsa->n, ret);
if (BN_cmp(ret, f))
res = f;
else
res = ret;
}
else
res = ret;
/* put in leading 0 bytes if the number is less than the
* length of the modulus */
j=BN_num_bytes(res);
i=BN_bn2bin(res,&(to[num-j]));
for (k=0; k<(num-i); k++)
to[k]=0;
r=num;
err:
if (ctx != NULL)
{
BN_CTX_end(ctx);
BN_CTX_free(ctx);
}
if (buf != NULL)
{
OPENSSL_cleanse(buf,num);
OPENSSL_free(buf);
}
return(r);
} | /* signing */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rsa/rsa_eay.c#L348-L478 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RSA_eay_public_decrypt | static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
BIGNUM *f,*ret;
int i,num=0,r= -1;
unsigned char *p;
unsigned char *buf=NULL;
BN_CTX *ctx=NULL;
if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_MODULUS_TOO_LARGE);
return -1;
}
if (BN_ucmp(rsa->n, rsa->e) <= 0)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);
return -1;
}
/* for large moduli, enforce exponent limit */
if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
{
if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);
return -1;
}
}
if((ctx = BN_CTX_new()) == NULL) goto err;
BN_CTX_start(ctx);
f = BN_CTX_get(ctx);
ret = BN_CTX_get(ctx);
num=BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num);
if(!f || !ret || !buf)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
goto err;
}
/* This check was for equality but PGP does evil things
* and chops off the top '0' bytes */
if (flen > num)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
goto err;
}
if (BN_bin2bn(from,flen,f) == NULL) goto err;
if (BN_ucmp(f, rsa->n) >= 0)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
goto err;
}
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))
goto err;
if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx,
rsa->_method_mod_n)) goto err;
if ((padding == RSA_X931_PADDING) && ((ret->d[0] & 0xf) != 12))
if (!BN_sub(ret, rsa->n, ret)) goto err;
p=buf;
i=BN_bn2bin(ret,p);
switch (padding)
{
case RSA_PKCS1_PADDING:
r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
break;
case RSA_X931_PADDING:
r=RSA_padding_check_X931(to,num,buf,i,num);
break;
case RSA_NO_PADDING:
r=RSA_padding_check_none(to,num,buf,i,num);
break;
default:
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
goto err;
}
if (r < 0)
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
err:
if (ctx != NULL)
{
BN_CTX_end(ctx);
BN_CTX_free(ctx);
}
if (buf != NULL)
{
OPENSSL_cleanse(buf,num);
OPENSSL_free(buf);
}
return(r);
} | /* signature verification */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rsa/rsa_eay.c#L611-L713 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RSA_generate_key_ex | int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
{
if(rsa->meth->rsa_keygen)
return rsa->meth->rsa_keygen(rsa, bits, e_value, cb);
return rsa_builtin_keygen(rsa, bits, e_value, cb);
} | /* NB: this wrapper would normally be placed in rsa_lib.c and the static
* implementation would probably be in rsa_eay.c. Nonetheless, is kept here so
* that we don't introduce a new linker dependency. Eg. any application that
* wasn't previously linking object code related to key-generation won't have to
* now just because key-generation is part of RSA_METHOD. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rsa/rsa_gen.c#L78-L83 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RSA_null_mod_exp | static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
{
...err(RSA_F_RSA_NULL_MOD_EXP, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
return -1;
} | /* not currently used */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rsa/rsa_null.c#L136-L140 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | RSA_X931_hash_id | int RSA_X931_hash_id(int nid)
{
switch (nid)
{
case NID_sha1:
return 0x33;
case NID_sha256:
return 0x34;
case NID_sha384:
return 0x36;
case NID_sha512:
return 0x35;
}
return -1;
} | /* Translate between X931 hash ids and NIDs */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/rsa/rsa_x931.c#L158-L176 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | sha512_block_data_order | static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num)
{
const SHA_LONG64 *W=in;
SHA_LONG64 A,E,T;
SHA_LONG64 X[9+80],*F;
int i;
while (num--) {
F = X+80;
A = ctx->h[0]; F[1] = ctx->h[1];
F[2] = ctx->h[2]; F[3] = ctx->h[3];
E = ctx->h[4]; F[5] = ctx->h[5];
F[6] = ctx->h[6]; F[7] = ctx->h[7];
for (i=0;i<16;i++,F--)
{
#ifdef B_ENDIAN
T = W[i];
#else
T = PULL64(W[i]);
#endif
F[0] = A;
F[4] = E;
F[8] = T;
T += F[7] + Sigma1(E) + Ch(E,F[5],F[6]) + K512[i];
E = F[3] + T;
A = T + Sigma0(A) + Maj(A,F[1],F[2]);
}
for (;i<80;i++,F--)
{
T = sigma0(F[8+16-1]);
T += sigma1(F[8+16-14]);
T += F[8+16] + F[8+16-9];
F[0] = A;
F[4] = E;
F[8] = T;
T += F[7] + Sigma1(E) + Ch(E,F[5],F[6]) + K512[i];
E = F[3] + T;
A = T + Sigma0(A) + Maj(A,F[1],F[2]);
}
ctx->h[0] += A; ctx->h[1] += F[1];
ctx->h[2] += F[2]; ctx->h[3] += F[3];
ctx->h[4] += E; ctx->h[5] += F[5];
ctx->h[6] += F[6]; ctx->h[7] += F[7];
W+=SHA_LBLOCK;
}
} | /*
* This code should give better results on 32-bit CPU with less than
* ~24 registers, both size and performance wise...
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/sha/sha512.c#L444-L495 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | STORE_destroy_method | void STORE_destroy_method(STORE_METHOD *store_method)
{
if (!store_method) return;
OPENSSL_free(store_method->name);
store_method->name = NULL;
OPENSSL_free(store_method);
} | /* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
(that is, it hasn't been allocated using STORE_create_method(), you deserve
anything Murphy can throw at you and more! You have been warned. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/store/str_meth.c#L78-L84 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_CONF_lookup_fail | static void TS_CONF_lookup_fail(const char *name, const char *tag)
{
fprintf(stderr, "variable lookup failed for %s::%s\n", name, tag);
} | /* Function definitions for handling configuration options. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_conf.c#L152-L155 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_ASN1_INTEGER_print_bio | int TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num)
{
BIGNUM num_bn;
int result = 0;
char *hex;
BN_init(&num_bn);
ASN1_INTEGER_to_BN(num, &num_bn);
if ((hex = BN_bn2hex(&num_bn)))
{
result = BIO_write(bio, "0x", 2) > 0;
result = result && BIO_write(bio, hex, strlen(hex)) > 0;
OPENSSL_free(hex);
}
BN_free(&num_bn);
return result;
} | /* Local function declarations. */
/* Function definitions. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_lib.c#L70-L87 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_REQ_print_bio | int TS_REQ_print_bio(BIO *bio, TS_REQ *a)
{
int v;
ASN1_OBJECT *policy_id;
const ASN1_INTEGER *nonce;
if (a == NULL) return 0;
v = TS_REQ_get_version(a);
BIO_printf(bio, "Version: %d\n", v);
TS_MSG_IMPRINT_print_bio(bio, TS_REQ_get_msg_imprint(a));
BIO_printf(bio, "Policy OID: ");
policy_id = TS_REQ_get_policy_id(a);
if (policy_id == NULL)
BIO_printf(bio, "unspecified\n");
else
TS_OBJ_print_bio(bio, policy_id);
BIO_printf(bio, "Nonce: ");
nonce = TS_REQ_get_nonce(a);
if (nonce == NULL)
BIO_printf(bio, "unspecified");
else
TS_ASN1_INTEGER_print_bio(bio, nonce);
BIO_write(bio, "\n", 1);
BIO_printf(bio, "Certificate required: %s\n",
TS_REQ_get_cert_req(a) ? "yes" : "no");
TS_ext_print_bio(bio, TS_REQ_get_exts(a));
return 1;
} | /* Function definitions. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_req_print.c#L68-L102 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_print_bio | int TS_RESP_print_bio(BIO *bio, TS_RESP *a)
{
TS_TST_INFO *tst_info;
BIO_printf(bio, "Status info:\n");
TS_STATUS_INFO_print_bio(bio, TS_RESP_get_status_info(a));
BIO_printf(bio, "\nTST info:\n");
tst_info = TS_RESP_get_tst_info(a);
if (tst_info != NULL)
TS_TST_INFO_print_bio(bio, TS_RESP_get_tst_info(a));
else
BIO_printf(bio, "Not included.\n");
return 1;
} | /* Function definitions. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_print.c#L80-L95 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | def_time_cb | static int def_time_cb(struct TS_resp_ctx *ctx, void *data,
long *sec, long *usec)
{
struct timeval tv;
if (gettimeofday(&tv, NULL) != 0)
{
TSerr(TS_F_DEF_TIME_CB, TS_R_TIME_SYSCALL_ERROR);
TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
"Time is not available.");
TS_RESP_CTX_add_failure_info(ctx, TS_INFO_TIME_NOT_AVAILABLE);
return 0;
}
/* Return time to caller. */
*sec = tv.tv_sec;
*usec = tv.tv_usec;
return 1;
} | /* Use the gettimeofday function call. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_sign.c#L111-L128 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | def_time_cb | static int def_time_cb(struct TS_resp_ctx *ctx, void *data,
long *sec, long *usec)
{
time_t t;
if (time(&t) == (time_t) -1)
{
TSerr(TS_F_DEF_TIME_CB, TS_R_TIME_SYSCALL_ERROR);
TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
"Time is not available.");
TS_RESP_CTX_add_failure_info(ctx, TS_INFO_TIME_NOT_AVAILABLE);
return 0;
}
/* Return time to caller, only second precision. */
*sec = (long) t;
*usec = 0;
return 1;
} | /* Use the time function call that provides only seconds precision. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_sign.c#L133-L150 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_CTX_init | static void TS_RESP_CTX_init(TS_RESP_CTX *ctx)
{
ctx->request = NULL;
ctx->response = NULL;
ctx->tst_info = NULL;
} | /* Initializes the variable part of the context. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_sign.c#L487-L492 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_CTX_cleanup | static void TS_RESP_CTX_cleanup(TS_RESP_CTX *ctx)
{
TS_REQ_free(ctx->request);
ctx->request = NULL;
TS_RESP_free(ctx->response);
ctx->response = NULL;
TS_TST_INFO_free(ctx->tst_info);
ctx->tst_info = NULL;
} | /* Cleans up the variable part of the context. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_sign.c#L495-L503 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_check_request | static int TS_RESP_check_request(TS_RESP_CTX *ctx)
{
TS_REQ *request = ctx->request;
TS_MSG_IMPRINT *msg_imprint;
X509_ALGOR *md_alg;
int md_alg_id;
const ASN1_OCTET_STRING *digest;
EVP_MD *md = NULL;
int i;
/* Checking request version. */
if (TS_REQ_get_version(request) != 1)
{
TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
"Bad request version.");
TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_REQUEST);
return 0;
}
/* Checking message digest algorithm. */
msg_imprint = TS_REQ_get_msg_imprint(request);
md_alg = TS_MSG_IMPRINT_get_algo(msg_imprint);
md_alg_id = OBJ_obj2nid(md_alg->algorithm);
for (i = 0; !md && i < sk_EVP_MD_num(ctx->mds); ++i)
{
EVP_MD *current_md = sk_EVP_MD_value(ctx->mds, i);
if (md_alg_id == EVP_MD_type(current_md))
md = current_md;
}
if (!md)
{
TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
"Message digest algorithm is "
"not supported.");
TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_ALG);
return 0;
}
/* No message digest takes parameter. */
if (md_alg->parameter
&& ASN1_TYPE_get(md_alg->parameter) != V_ASN1_NULL)
{
TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
"Superfluous message digest "
"parameter.");
TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_ALG);
return 0;
}
/* Checking message digest size. */
digest = TS_MSG_IMPRINT_get_msg(msg_imprint);
if (digest->length != EVP_MD_size(md))
{
TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
"Bad message digest.");
TS_RESP_CTX_add_failure_info(ctx, TS_INFO_BAD_DATA_FORMAT);
return 0;
}
return 1;
} | /* Checks the format and content of the request. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_sign.c#L506-L565 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_process_extensions | static int TS_RESP_process_extensions(TS_RESP_CTX *ctx)
{
STACK_OF(X509_EXTENSION) *exts = TS_REQ_get_exts(ctx->request);
int i;
int ok = 1;
for (i = 0; ok && i < sk_X509_EXTENSION_num(exts); ++i)
{
X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);
/* XXXXX The last argument was previously
(void *)ctx->extension_cb, but ISO C doesn't permit
converting a function pointer to void *. For lack of
better information, I'm placing a NULL there instead.
The callback can pick its own address out from the ctx
anyway...
*/
ok = (*ctx->extension_cb)(ctx, ext, NULL);
}
return ok;
} | /* Processing the extensions of the request. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_sign.c#L685-L705 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_sign | static int TS_RESP_sign(TS_RESP_CTX *ctx)
{
int ret = 0;
PKCS7 *p7 = NULL;
PKCS7_SIGNER_INFO *si;
STACK_OF(X509) *certs; /* Certificates to include in sc. */
ESS_SIGNING_CERT *sc = NULL;
ASN1_OBJECT *oid;
BIO *p7bio = NULL;
int i;
/* Check if signcert and pkey match. */
if (!X509_check_private_key(ctx->signer_cert, ctx->signer_key)) {
TSerr(TS_F_TS_RESP_SIGN,
TS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
goto err;
}
/* Create a new PKCS7 signed object. */
if (!(p7 = PKCS7_new())) {
TSerr(TS_F_TS_RESP_SIGN, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!PKCS7_set_type(p7, NID_pkcs7_signed)) goto err;
/* Force SignedData version to be 3 instead of the default 1. */
if (!ASN1_INTEGER_set(p7->d.sign->version, 3)) goto err;
/* Add signer certificate and optional certificate chain. */
if (TS_REQ_get_cert_req(ctx->request))
{
PKCS7_add_certificate(p7, ctx->signer_cert);
if (ctx->certs)
{
for(i = 0; i < sk_X509_num(ctx->certs); ++i)
{
X509 *cert = sk_X509_value(ctx->certs, i);
PKCS7_add_certificate(p7, cert);
}
}
}
/* Add a new signer info. */
if (!(si = PKCS7_add_signature(p7, ctx->signer_cert,
ctx->signer_key, EVP_sha1())))
{
TSerr(TS_F_TS_RESP_SIGN, TS_R_PKCS7_ADD_SIGNATURE_ERROR);
goto err;
}
/* Add content type signed attribute to the signer info. */
oid = OBJ_nid2obj(NID_id_smime_ct_TSTInfo);
if (!PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
V_ASN1_OBJECT, oid))
{
TSerr(TS_F_TS_RESP_SIGN, TS_R_PKCS7_ADD_SIGNED_ATTR_ERROR);
goto err;
}
/* Create the ESS SigningCertificate attribute which contains
the signer certificate id and optionally the certificate chain. */
certs = ctx->flags & TS_ESS_CERT_ID_CHAIN ? ctx->certs : NULL;
if (!(sc = ESS_SIGNING_CERT_new_init(ctx->signer_cert, certs)))
goto err;
/* Add SigningCertificate signed attribute to the signer info. */
if (!ESS_add_signing_cert(si, sc))
{
TSerr(TS_F_TS_RESP_SIGN, TS_R_ESS_ADD_SIGNING_CERT_ERROR);
goto err;
}
/* Add a new empty NID_id_smime_ct_TSTInfo encapsulated content. */
if (!TS_TST_INFO_content_new(p7)) goto err;
/* Add the DER encoded tst_info to the PKCS7 structure. */
if (!(p7bio = PKCS7_dataInit(p7, NULL))) {
TSerr(TS_F_TS_RESP_SIGN, ERR_R_MALLOC_FAILURE);
goto err;
}
/* Convert tst_info to DER. */
if (!i2d_TS_TST_INFO_bio(p7bio, ctx->tst_info))
{
TSerr(TS_F_TS_RESP_SIGN, TS_R_TS_DATASIGN);
goto err;
}
/* Create the signature and add it to the signer info. */
if (!PKCS7_dataFinal(p7, p7bio))
{
TSerr(TS_F_TS_RESP_SIGN, TS_R_TS_DATASIGN);
goto err;
}
/* Set new PKCS7 and TST_INFO objects. */
TS_RESP_set_tst_info(ctx->response, p7, ctx->tst_info);
p7 = NULL; /* Ownership is lost. */
ctx->tst_info = NULL; /* Ownership is lost. */
ret = 1;
err:
if (!ret)
TS_RESP_CTX_set_status_info_cond(ctx, TS_STATUS_REJECTION,
"Error during signature "
"generation.");
BIO_free_all(p7bio);
ESS_SIGNING_CERT_free(sc);
PKCS7_free(p7);
return ret;
} | /* Functions for signing the TS_TST_INFO structure of the context. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_sign.c#L708-L818 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_set_status_info | int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info)
{
TS_STATUS_INFO *new_status_info;
if (a->status_info == status_info)
return 1;
new_status_info = TS_STATUS_INFO_dup(status_info);
if (new_status_info == NULL)
{
TSerr(TS_F_TS_RESP_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE);
return 0;
}
TS_STATUS_INFO_free(a->status_info);
a->status_info = new_status_info;
return 1;
} | /* Function definitions. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_utils.c#L67-L83 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_set_tst_info | void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info)
{
/* Set new PKCS7 and TST_INFO objects. */
PKCS7_free(a->token);
a->token = p7;
TS_TST_INFO_free(a->tst_info);
a->tst_info = tst_info;
} | /* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_utils.c#L91-L98 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_verify_signature | int TS_RESP_verify_signature(PKCS7 *token, STACK_OF(X509) *certs,
X509_STORE *store, X509 **signer_out)
{
STACK_OF(PKCS7_SIGNER_INFO) *sinfos = NULL;
PKCS7_SIGNER_INFO *si;
STACK_OF(X509) *signers = NULL;
X509 *signer;
STACK_OF(X509) *chain = NULL;
char buf[4096];
int i, j = 0, ret = 0;
BIO *p7bio = NULL;
/* Some sanity checks first. */
if (!token)
{
TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_INVALID_NULL_POINTER);
goto err;
}
/* Check for the correct content type */
if(!PKCS7_type_is_signed(token))
{
TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_WRONG_CONTENT_TYPE);
goto err;
}
/* Check if there is one and only one signer. */
sinfos = PKCS7_get_signer_info(token);
if (!sinfos || sk_PKCS7_SIGNER_INFO_num(sinfos) != 1)
{
TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE,
TS_R_THERE_MUST_BE_ONE_SIGNER);
goto err;
}
si = sk_PKCS7_SIGNER_INFO_value(sinfos, 0);
/* Check for no content: no data to verify signature. */
if (PKCS7_get_detached(token))
{
TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_NO_CONTENT);
goto err;
}
/* Get hold of the signer certificate, search only internal
certificates if it was requested. */
signers = PKCS7_get0_signers(token, certs, 0);
if (!signers || sk_X509_num(signers) != 1) goto err;
signer = sk_X509_value(signers, 0);
/* Now verify the certificate. */
if (!TS_verify_cert(store, certs, signer, &chain)) goto err;
/* Check if the signer certificate is consistent with the
ESS extension. */
if (!TS_check_signing_certs(si, chain)) goto err;
/* Creating the message digest. */
p7bio = PKCS7_dataInit(token, NULL);
/* We now have to 'read' from p7bio to calculate digests etc. */
while ((i = BIO_read(p7bio,buf,sizeof(buf))) > 0);
/* Verifying the signature. */
j = PKCS7_signatureVerify(p7bio, token, si, signer);
if (j <= 0)
{
TSerr(TS_F_TS_RESP_VERIFY_SIGNATURE, TS_R_SIGNATURE_FAILURE);
goto err;
}
/* Return the signer certificate if needed. */
if (signer_out)
{
*signer_out = signer;
CRYPTO_add(&signer->references, 1, CRYPTO_LOCK_X509);
}
ret = 1;
err:
BIO_free_all(p7bio);
sk_X509_pop_free(chain, X509_free);
sk_X509_free(signers);
return ret;
} | /* Functions for verifying a signed TS_TST_INFO structure. */
/*
* This function carries out the following tasks:
* - Checks if there is one and only one signer.
* - Search for the signing certificate in 'certs' and in the response.
* - Check the extended key usage and key usage fields of the signer
* certificate (done by the path validation).
* - Build and validate the certificate path.
* - Check if the certificate path meets the requirements of the
* SigningCertificate ESS signed attribute.
* - Verify the signature value.
* - Returns the signer certificate in 'signer', if 'signer' is not NULL.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_verify.c#L140-L225 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_verify_cert | static int TS_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted,
X509 *signer, STACK_OF(X509) **chain)
{
X509_STORE_CTX cert_ctx;
int i;
int ret = 1;
/* chain is an out argument. */
*chain = NULL;
X509_STORE_CTX_init(&cert_ctx, store, signer, untrusted);
X509_STORE_CTX_set_purpose(&cert_ctx, X509_PURPOSE_TIMESTAMP_SIGN);
i = X509_verify_cert(&cert_ctx);
if (i <= 0)
{
int j = X509_STORE_CTX_get_error(&cert_ctx);
TSerr(TS_F_TS_VERIFY_CERT, TS_R_CERTIFICATE_VERIFY_ERROR);
ERR_add_error_data(2, "Verify error:",
X509_verify_cert_error_string(j));
ret = 0;
}
else
{
/* Get a copy of the certificate chain. */
*chain = X509_STORE_CTX_get1_chain(&cert_ctx);
}
X509_STORE_CTX_cleanup(&cert_ctx);
return ret;
} | /*
* The certificate chain is returned in chain. Caller is responsible for
* freeing the vector.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_verify.c#L231-L260 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_find_cert | static int TS_find_cert(STACK_OF(ESS_CERT_ID) *cert_ids, X509 *cert)
{
int i;
if (!cert_ids || !cert) return -1;
/* Recompute SHA1 hash of certificate if necessary (side effect). */
X509_check_purpose(cert, -1, 0);
/* Look for cert in the cert_ids vector. */
for (i = 0; i < sk_ESS_CERT_ID_num(cert_ids); ++i)
{
ESS_CERT_ID *cid = sk_ESS_CERT_ID_value(cert_ids, i);
/* Check the SHA-1 hash first. */
if (cid->hash->length == sizeof(cert->sha1_hash)
&& !memcmp(cid->hash->data, cert->sha1_hash,
sizeof(cert->sha1_hash)))
{
/* Check the issuer/serial as well if specified. */
ESS_ISSUER_SERIAL *is = cid->issuer_serial;
if (!is || !TS_issuer_serial_cmp(is, cert->cert_info))
return i;
}
}
return -1;
} | /* Returns < 0 if certificate is not found, certificate index otherwise. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_verify.c#L308-L335 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_verify_response | int TS_RESP_verify_response(TS_VERIFY_CTX *ctx, TS_RESP *response)
{
PKCS7 *token = TS_RESP_get_token(response);
TS_TST_INFO *tst_info = TS_RESP_get_tst_info(response);
int ret = 0;
/* Check if we have a successful TS_TST_INFO object in place. */
if (!TS_check_status_info(response)) goto err;
/* Check the contents of the time stamp token. */
if (!int_TS_RESP_verify_token(ctx, token, tst_info))
goto err;
ret = 1;
err:
return ret;
} | /*
* Verifies whether 'response' contains a valid response with regards
* to the settings of the context:
* - Gives an error message if the TS_TST_INFO is not present.
* - Calls _TS_RESP_verify_token to verify the token content.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_verify.c#L362-L378 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_RESP_verify_token | int TS_RESP_verify_token(TS_VERIFY_CTX *ctx, PKCS7 *token)
{
TS_TST_INFO *tst_info = PKCS7_to_TS_TST_INFO(token);
int ret = 0;
if (tst_info)
{
ret = int_TS_RESP_verify_token(ctx, token, tst_info);
TS_TST_INFO_free(tst_info);
}
return ret;
} | /*
* Tries to extract a TS_TST_INFO structure from the PKCS7 token and
* calls the internal int_TS_RESP_verify_token function for verifying it.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_verify.c#L384-L394 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | int_TS_RESP_verify_token | static int int_TS_RESP_verify_token(TS_VERIFY_CTX *ctx,
PKCS7 *token, TS_TST_INFO *tst_info)
{
X509 *signer = NULL;
GENERAL_NAME *tsa_name = TS_TST_INFO_get_tsa(tst_info);
X509_ALGOR *md_alg = NULL;
unsigned char *imprint = NULL;
unsigned imprint_len = 0;
int ret = 0;
/* Verify the signature. */
if ((ctx->flags & TS_VFY_SIGNATURE)
&& !TS_RESP_verify_signature(token, ctx->certs, ctx->store,
&signer))
goto err;
/* Check version number of response. */
if ((ctx->flags & TS_VFY_VERSION)
&& TS_TST_INFO_get_version(tst_info) != 1)
{
TSerr(TS_F_INT_TS_RESP_VERIFY_TOKEN, TS_R_UNSUPPORTED_VERSION);
goto err;
}
/* Check policies. */
if ((ctx->flags & TS_VFY_POLICY)
&& !TS_check_policy(ctx->policy, tst_info))
goto err;
/* Check message imprints. */
if ((ctx->flags & TS_VFY_IMPRINT)
&& !TS_check_imprints(ctx->md_alg, ctx->imprint, ctx->imprint_len,
tst_info))
goto err;
/* Compute and check message imprints. */
if ((ctx->flags & TS_VFY_DATA)
&& (!TS_compute_imprint(ctx->data, tst_info,
&md_alg, &imprint, &imprint_len)
|| !TS_check_imprints(md_alg, imprint, imprint_len, tst_info)))
goto err;
/* Check nonces. */
if ((ctx->flags & TS_VFY_NONCE)
&& !TS_check_nonces(ctx->nonce, tst_info))
goto err;
/* Check whether TSA name and signer certificate match. */
if ((ctx->flags & TS_VFY_SIGNER)
&& tsa_name && !TS_check_signer_name(tsa_name, signer))
{
TSerr(TS_F_INT_TS_RESP_VERIFY_TOKEN, TS_R_TSA_NAME_MISMATCH);
goto err;
}
/* Check whether the TSA is the expected one. */
if ((ctx->flags & TS_VFY_TSA_NAME)
&& !TS_check_signer_name(ctx->tsa_name, signer))
{
TSerr(TS_F_INT_TS_RESP_VERIFY_TOKEN, TS_R_TSA_UNTRUSTED);
goto err;
}
ret = 1;
err:
X509_free(signer);
X509_ALGOR_free(md_alg);
OPENSSL_free(imprint);
return ret;
} | /*
* Verifies whether the 'token' contains a valid time stamp token
* with regards to the settings of the context. Only those checks are
* carried out that are specified in the context:
* - Verifies the signature of the TS_TST_INFO.
* - Checks the version number of the response.
* - Check if the requested and returned policies math.
* - Check if the message imprints are the same.
* - Check if the nonces are the same.
* - Check if the TSA name matches the signer.
* - Check if the TSA name is the expected TSA.
*/ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_verify.c#L408-L477 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_check_signer_name | static int TS_check_signer_name(GENERAL_NAME *tsa_name, X509 *signer)
{
STACK_OF(GENERAL_NAME) *gen_names = NULL;
int idx = -1;
int found = 0;
/* Check the subject name first. */
if (tsa_name->type == GEN_DIRNAME
&& X509_name_cmp(tsa_name->d.dirn, signer->cert_info->subject) == 0)
return 1;
/* Check all the alternative names. */
gen_names = X509_get_ext_d2i(signer, NID_subject_alt_name,
NULL, &idx);
while (gen_names != NULL
&& !(found = TS_find_name(gen_names, tsa_name) >= 0))
{
/* Get the next subject alternative name,
although there should be no more than one. */
GENERAL_NAMES_free(gen_names);
gen_names = X509_get_ext_d2i(signer, NID_subject_alt_name,
NULL, &idx);
}
if (gen_names) GENERAL_NAMES_free(gen_names);
return found;
} | /* Check if the specified TSA name matches either the subject
or one of the subject alternative names of the TSA certificate. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_verify.c#L686-L712 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
BigWorld-Engine-14.4.1 | github_2023 | v2v3v4 | c | TS_find_name | static int TS_find_name(STACK_OF(GENERAL_NAME) *gen_names, GENERAL_NAME *name)
{
int i, found;
for (i = 0, found = 0; !found && i < sk_GENERAL_NAME_num(gen_names);
++i)
{
GENERAL_NAME *current = sk_GENERAL_NAME_value(gen_names, i);
found = GENERAL_NAME_cmp(current, name) == 0;
}
return found ? i - 1 : -1;
} | /* Returns 1 if name is in gen_names, 0 otherwise. */ | https://github.com/v2v3v4/BigWorld-Engine-14.4.1/blob/4389085c8ce35cff887a4cc18fc47d1133d89ffb/programming/bigworld/third_party/openssl/crypto/ts/ts_rsp_verify.c#L715-L725 | 4389085c8ce35cff887a4cc18fc47d1133d89ffb |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.