engines/e_cswift.c:1002: error: INTEGER_OVERFLOW_L2
  ([0, `sig->r->top`] - 1):unsigned64 by call to `BN_bn2bin`.
Showing all 9 steps of the trace


engines/e_cswift.c:919:1: Parameter `sig->r->top`
917.   	}
918.   
919. > static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
920.   				DSA_SIG *sig, DSA *dsa)
921.   	{

engines/e_cswift.c:1002:40: Call
1000.   	arg[1].value = (unsigned char *)argument->d;
1001.   	memset(arg[1].value, 0, 40);
1002.   	BN_bn2bin(sig->r, arg[1].value + 20 - BN_num_bytes(sig->r));
                                               ^
1003.   	BN_bn2bin(sig->s, arg[1].value + 40 - BN_num_bytes(sig->s));
1004.   	res.nbytes = 4; /* unsigned long */

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
  246.   	}
  247.   
  248. > int BN_num_bits(const BIGNUM *a)
  249.   	{
  250.   	int i = a->top - 1;

engines/e_cswift.c:1002:2: Call
1000.   	arg[1].value = (unsigned char *)argument->d;
1001.   	memset(arg[1].value, 0, 40);
1002.   	BN_bn2bin(sig->r, arg[1].value + 20 - BN_num_bytes(sig->r));
         ^
1003.   	BN_bn2bin(sig->s, arg[1].value + 40 - BN_num_bytes(sig->s));
1004.   	res.nbytes = 4; /* unsigned long */

crypto/bn/bn_lib.c:641:1: Parameter `a->top`
  639.   
  640.   /* ignore negative */
  641. > int BN_bn2bin(const BIGNUM *a, unsigned char *to)
  642.   	{
  643.   	int n,i;

crypto/bn/bn_lib.c:647:6: Call
  645.   
  646.   	bn_check_top(a);
  647.   	n=i=BN_num_bytes(a);
              ^
  648.   	while (i--)
  649.   		{

crypto/bn/bn_lib.c:248:1: <LHS trace>
246.   	}
247.   
248. > int BN_num_bits(const BIGNUM *a)
249.   	{
250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
    246.   	}
    247.   
    248. > int BN_num_bits(const BIGNUM *a)
    249.   	{
    250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:250:2: Binary operation: ([0, sig->r->top] - 1):unsigned64 by call to `BN_bn2bin` 
    248.   int BN_num_bits(const BIGNUM *a)
    249.   	{
    250.   	int i = a->top - 1;
            ^
    251.   	bn_check_top(a);
    252.   

int BN_num_bits(const BIGNUM *a)
	{
	int i = a->top - 1;
	bn_check_top(a);
	if (BN_is_zero(a)) return 0;
	return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
	}
['static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,\n\t\t\t\tDSA_SIG *sig, DSA *dsa)\n\t{\n\tSW_CONTEXT_HANDLE hac;\n\tSW_PARAM sw_param;\n\tSW_STATUS sw_status;\n\tSW_LARGENUMBER arg[2], res;\n\tunsigned long sig_result;\n\tBN_CTX *ctx;\n\tBIGNUM *dsa_p = NULL;\n\tBIGNUM *dsa_q = NULL;\n\tBIGNUM *dsa_g = NULL;\n\tBIGNUM *dsa_key = NULL;\n\tBIGNUM *argument = NULL;\n\tint to_return = -1;\n\tint acquired = 0;\n\tif((ctx = BN_CTX_new()) == NULL)\n\t\tgoto err;\n\tif(!get_context(&hac))\n\t\t{\n\t\tCSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_UNIT_FAILURE);\n\t\tgoto err;\n\t\t}\n\tacquired = 1;\n\tBN_CTX_start(ctx);\n\tdsa_p = BN_CTX_get(ctx);\n\tdsa_q = BN_CTX_get(ctx);\n\tdsa_g = BN_CTX_get(ctx);\n\tdsa_key = BN_CTX_get(ctx);\n\targument = BN_CTX_get(ctx);\n\tif(!argument)\n\t\t{\n\t\tCSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BN_CTX_FULL);\n\t\tgoto err;\n\t\t}\n\tif(!bn_wexpand(dsa_p, dsa->p->top) ||\n\t\t\t!bn_wexpand(dsa_q, dsa->q->top) ||\n\t\t\t!bn_wexpand(dsa_g, dsa->g->top) ||\n\t\t\t!bn_wexpand(dsa_key, dsa->pub_key->top) ||\n\t\t\t!bn_wexpand(argument, 40))\n\t\t{\n\t\tCSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BN_EXPAND_FAIL);\n\t\tgoto err;\n\t\t}\n\tsw_param.type = SW_ALG_DSA;\n\tsw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p,\n\t\t\t\t(unsigned char *)dsa_p->d);\n\tsw_param.up.dsa.p.value = (unsigned char *)dsa_p->d;\n\tsw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q,\n\t\t\t\t(unsigned char *)dsa_q->d);\n\tsw_param.up.dsa.q.value = (unsigned char *)dsa_q->d;\n\tsw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g,\n\t\t\t\t(unsigned char *)dsa_g->d);\n\tsw_param.up.dsa.g.value = (unsigned char *)dsa_g->d;\n\tsw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->pub_key,\n\t\t\t\t(unsigned char *)dsa_key->d);\n\tsw_param.up.dsa.key.value = (unsigned char *)dsa_key->d;\n\tsw_status = p_CSwift_AttachKeyParam(hac, &sw_param);\n\tswitch(sw_status)\n\t\t{\n\tcase SW_OK:\n\t\tbreak;\n\tcase SW_ERR_INPUT_SIZE:\n\t\tCSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BAD_KEY_SIZE);\n\t\tgoto err;\n\tdefault:\n\t\t{\n\t\tchar tmpbuf[DECIMAL_SIZE(sw_status)+1];\n\t\tCSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED);\n\t\tsprintf(tmpbuf, "%ld", sw_status);\n\t\tERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);\n\t\t}\n\t\tgoto err;\n\t\t}\n\targ[0].nbytes = dgst_len;\n\targ[0].value = (unsigned char *)dgst;\n\targ[1].nbytes = 40;\n\targ[1].value = (unsigned char *)argument->d;\n\tmemset(arg[1].value, 0, 40);\n\tBN_bn2bin(sig->r, arg[1].value + 20 - BN_num_bytes(sig->r));\n\tBN_bn2bin(sig->s, arg[1].value + 40 - BN_num_bytes(sig->s));\n\tres.nbytes = 4;\n\tres.value = (unsigned char *)(&sig_result);\n\tsw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_VERIFY, arg, 2,\n\t\t&res, 1);\n\tif(sw_status != SW_OK)\n\t\t{\n\t\tchar tmpbuf[DECIMAL_SIZE(sw_status)+1];\n\t\tCSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED);\n\t\tsprintf(tmpbuf, "%ld", sw_status);\n\t\tERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);\n\t\tgoto err;\n\t\t}\n\tto_return = ((sig_result == 0) ? 0 : 1);\nerr:\n\tif(acquired)\n\t\trelease_context(hac);\n\tif(ctx)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\treturn to_return;\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}', 'int BN_bn2bin(const BIGNUM *a, unsigned char *to)\n\t{\n\tint n,i;\n\tBN_ULONG l;\n\tbn_check_top(a);\n\tn=i=BN_num_bytes(a);\n\twhile (i--)\n\t\t{\n\t\tl=a->d[i/BN_BYTES];\n\t\t*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;\n\t\t}\n\treturn(n);\n\t}']