Datasets:

Modalities:
Tabular
Text
Formats:
parquet
ArXiv:
Tags:
code
Libraries:
Datasets
Dask
License:
claudios commited on
Commit
60de6a2
1 Parent(s): 1c3ba1b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +529 -0
README.md CHANGED
@@ -1,4 +1,5 @@
1
  ---
 
2
  dataset_info:
3
  - config_name: code
4
  features:
@@ -123,4 +124,532 @@ configs:
123
  path: trace/dev-*
124
  - split: test
125
  path: trace/test-*
 
 
 
 
 
126
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ arxiv: 2102.07995
3
  dataset_info:
4
  - config_name: code
5
  features:
 
124
  path: trace/dev-*
125
  - split: test
126
  path: trace/test-*
127
+ license: apache-2.0
128
+ task_categories:
129
+ - text-classification
130
+ tags:
131
+ - code
132
  ---
133
+
134
+ # D2A: A Dataset Built for AI-Based Vulnerability Detection Methods Using Differential Analysis
135
+ This is an unofficial HuggingFace upload of the D2A dataset from "[D2A: A Dataset Built for AI-Based Vulnerability Detection Methods Using Differential Analysis](https://arxiv.org/abs/2102.07995)". "Test" splits have all labels as -1 as they are not provided.
136
+
137
+ ***
138
+
139
+ # D2A Leaderboard Data
140
+
141
+ This document describes D2A V1 Leaderboard data. You can download them from the Leaderboard section of the [D2A Dataset](https://dax-cdn.cdn.appdomain.cloud/dax-d2a/1.1.0/d2a.html?cm_mc_uid=52096571630515722723826&cm_mc_sid_50200000=65851751618339788874&_ga=2.42786284.851757668.1618339789-1229357178.1617837310) page. To begin download directly you can click [here](https://dax-cdn.cdn.appdomain.cloud/dax-d2a/1.1.0/d2a_leaderboard_data.tar.gz).
142
+
143
+ ## Source files:
144
+
145
+ The files were created using the [default security errors](#default-security-errors) of datasets Libav, OpenSSL, Nginx, Httpd and Libtiff from [D2A](https://developer.ibm.com/exchanges/data/all/d2a/).
146
+
147
+ There are 4 directories corresponding to 4 tasks of the leaderboard. Each directory contains 3 csv files corresponding to the train (80%), dev (10%) and test (10%) split.
148
+ The columns in the split files are identical except the test split which does not contain the label column.
149
+
150
+ ## Columns:
151
+
152
+ 1. **id**: A unique id for every example in a task.
153
+ 2. **label**: Values are 0 or 1.
154
+ 1. Value 0: No vulnerability/defect in the example.
155
+ 2. Value 1: Example contains some vulnerability/defect.
156
+ 3. **trace**: Bug trace or bug report generated by Infer static analyzer. Infer predictions contain a lot of False positives which is why even 0 label examples have a bug report.
157
+ 4. **bug_function/code**: Full source code of the function where the vulnerability originates.
158
+ 5. **bug_url**: URL of the file which contains the bug_function.
159
+ 6. **functions**: Full source code of all the functions in the bug trace, with the duplicates removed. This will include the function in bug_function.
160
+
161
+ ## Default Security Errors:
162
+
163
+ These are security errors enabled by default by Infer.
164
+
165
+ * BIABD_USE_AFTER_FREE
166
+ * BUFFER_OVERRUN_L1
167
+ * BUFFER_OVERRUN_L2
168
+ * BUFFER_OVERRUN_L3
169
+ * BUFFER_OVERRUN_R2
170
+ * BUFFER_OVERRUN_S2
171
+ * BUFFER_OVERRUN_T1
172
+ * INTEGER_OVERFLOW_L1
173
+ * INTEGER_OVERFLOW_L2
174
+ * INTEGER_OVERFLOW_R2
175
+ * MEMORY_LEAK
176
+ * NULL_DEREFERENCE
177
+ * RESOURCE_LEAK
178
+ * LAB_RESOURCE_LEAK
179
+ * UNINITIALIZED_VALUE
180
+ * USE_AFTER_DELETE
181
+ * USE_AFTER_FREE
182
+ * USE_AFTER_LIFETIME
183
+
184
+ ## Data Examples:
185
+
186
+ 1. Trace:
187
+
188
+ ```"test/bntest.c:1802: error: BUFFER_OVERRUN_L3
189
+ Offset: [4, +oo] (‚áê [0, +oo] + 4) Size: [0, 8388607] by call to `BN_mul`.
190
+ Showing all 12 steps of the trace
191
+
192
+
193
+ test/bntest.c:1798:10: Call
194
+ 1796.
195
+ 1797. /* Test that BN_mul never gives negative zero. */
196
+ 1798. if (!BN_set_word(a, 1))
197
+ ^
198
+ 1799. goto err;
199
+ 1800. BN_set_negative(a, 1);
200
+
201
+ crypto/bn/bn_lib.c:463:1: Parameter `*a->d`
202
+ 461. }
203
+ 462.
204
+ 463. > int BN_set_word(BIGNUM *a, BN_ULONG w)
205
+ 464. {
206
+ 465. bn_check_top(a);
207
+
208
+ crypto/bn/bn_lib.c:466:9: Call
209
+ 464. {
210
+ 465. bn_check_top(a);
211
+ 466. if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
212
+ ^
213
+ 467. return (0);
214
+ 468. a->neg = 0;
215
+
216
+ crypto/bn/bn_lcl.h:676:1: Parameter `*a->d`
217
+ 674. int bn_probable_prime_dh_coprime(BIGNUM *rnd, int bits, BN_CTX *ctx);
218
+ 675.
219
+ 676. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
220
+ 677. {
221
+ 678. if (bits > (INT_MAX - BN_BITS2 + 1))
222
+
223
+ test/bntest.c:1802:10: Call
224
+ 1800. BN_set_negative(a, 1);
225
+ 1801. BN_zero(b);
226
+ 1802. if (!BN_mul(c, a, b, ctx))
227
+ ^
228
+ 1803. goto err;
229
+ 1804. if (!BN_is_zero(c) || BN_is_negative(c)) {
230
+
231
+ crypto/bn/bn_mul.c:828:1: Parameter `*b->d`
232
+ 826. #endif /* BN_RECURSION */
233
+ 827.
234
+ 828. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
235
+ 829. {
236
+ 830. int ret = 0;
237
+
238
+ crypto/bn/bn_mul.c:909:17: Call
239
+ 907. if (bn_wexpand(rr, k * 4) == NULL)
240
+ 908. goto err;
241
+ 909. bn_mul_part_recursive(rr->d, a->d, b->d,
242
+ ^
243
+ 910. j, al - j, bl - j, t->d);
244
+ 911. } else { /* al <= j || bl <= j */
245
+
246
+ crypto/bn/bn_mul.c:480:1: Parameter `*b`
247
+ 478. */
248
+ 479. /* tnX may not be negative but less than n */
249
+ 480. > void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
250
+ 481. int tna, int tnb, BN_ULONG *t)
251
+ 482. {
252
+
253
+ crypto/bn/bn_mul.c:488:9: Call
254
+ 486.
255
+ 487. if (n < 8) {
256
+ 488. bn_mul_normal(r, a, n + tna, b, n + tnb);
257
+ ^
258
+ 489. return;
259
+ 490. }
260
+
261
+ crypto/bn/bn_mul.c:983:1: <Length trace>
262
+ 981. }
263
+ 982.
264
+ 983. > void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
265
+ 984. {
266
+ 985. BN_ULONG *rr;
267
+
268
+ crypto/bn/bn_mul.c:983:1: Parameter `*b`
269
+ 981. }
270
+ 982.
271
+ 983. > void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
272
+ 984. {
273
+ 985. BN_ULONG *rr;
274
+
275
+ crypto/bn/bn_mul.c:1018:50: Array access: Offset: [4, +oo] (‚áê [0, +oo] + 4) Size: [0, 8388607] by call to `BN_mul`
276
+ 1016. if (--nb <= 0)
277
+ 1017. return;
278
+ 1018. rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
279
+ ^
280
+ 1019. rr += 4;
281
+ 1020. r += 4;
282
+ "
283
+ ```
284
+
285
+ 2. Bug URL:
286
+
287
+ ```
288
+ https://github.com/openssl/openssl/blob/0282aeb690d63fab73a07191b63300a2fe30d212/crypto/bn/bn_mul.c/#L1018
289
+ ```
290
+
291
+ 3. Bug Function:
292
+
293
+ ```
294
+ "void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
295
+ {
296
+ BN_ULONG *rr;
297
+ if (na < nb) {
298
+ int itmp;
299
+ BN_ULONG *ltmp;
300
+ itmp = na;
301
+ na = nb;
302
+ nb = itmp;
303
+ ltmp = a;
304
+ a = b;
305
+ b = ltmp;
306
+ }
307
+ rr = &(r[na]);
308
+ if (nb <= 0) {
309
+ (void)bn_mul_words(r, a, na, 0);
310
+ return;
311
+ } else
312
+ rr[0] = bn_mul_words(r, a, na, b[0]);
313
+ for (;;) {
314
+ if (--nb <= 0)
315
+ return;
316
+ rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);
317
+ if (--nb <= 0)
318
+ return;
319
+ rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);
320
+ if (--nb <= 0)
321
+ return;
322
+ rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);
323
+ if (--nb <= 0)
324
+ return;
325
+ rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
326
+ rr += 4;
327
+ r += 4;
328
+ b += 4;
329
+ }
330
+ }"
331
+ ```
332
+
333
+ 4. Functions:
334
+
335
+ ```
336
+ [
337
+ 'static int test_negzero() {
338
+ BIGNUM * a = BN_new();
339
+ BIGNUM * b = BN_new();
340
+ BIGNUM * c = BN_new();
341
+ BIGNUM * d = BN_new();
342
+ BIGNUM * numerator = NULL, * denominator = NULL;
343
+ int consttime, st = 0;
344
+ if (a == NULL || b == NULL || c == NULL || d == NULL) goto err;
345
+ if (!BN_set_word(a, 1)) goto err;
346
+ BN_set_negative(a, 1);
347
+ BN_zero(b);
348
+ if (!BN_mul(c, a, b, ctx)) goto err;
349
+ if (!BN_is_zero(c) || BN_is_negative(c)) {
350
+ fprintf(stderr, "Multiplication test failed!");
351
+ goto err;
352
+ }
353
+ for (consttime = 0; consttime < 2; consttime++) {
354
+ numerator = BN_new();
355
+ denominator = BN_new();
356
+ if (numerator == NULL || denominator == NULL) goto err;
357
+ if (consttime) {
358
+ BN_set_flags(numerator, BN_FLG_CONSTTIME);
359
+ BN_set_flags(denominator, BN_FLG_CONSTTIME);
360
+ }
361
+ if (!BN_set_word(numerator, 1) || !BN_set_word(denominator, 2)) goto err;
362
+ BN_set_negative(numerator, 1);
363
+ if (!BN_div(a, b, numerator, denominator, ctx)) goto err;
364
+ if (!BN_is_zero(a) || BN_is_negative(a)) {
365
+ fprintf(stderr, "Incorrect quotient (consttime = %d).", consttime);
366
+ goto err;
367
+ }
368
+ if (!BN_set_word(denominator, 1)) goto err;
369
+ if (!BN_div(a, b, numerator, denominator, ctx)) goto err;
370
+ if (!BN_is_zero(b) || BN_is_negative(b)) {
371
+ fprintf(stderr, "Incorrect remainder (consttime = %d).", consttime);
372
+ goto err;
373
+ }
374
+ BN_free(numerator);
375
+ BN_free(denominator);
376
+ numerator = denominator = NULL;
377
+ }
378
+ BN_zero(a);
379
+ BN_set_negative(a, 1);
380
+ if (BN_is_negative(a)) {
381
+ fprintf(stderr, "BN_set_negative produced a negative zero.");
382
+ goto err;
383
+ }
384
+ st = 1;
385
+ err: BN_free(a);
386
+ BN_free(b);
387
+ BN_free(c);
388
+ BN_free(d);
389
+ BN_free(numerator);
390
+ BN_free(denominator);
391
+ return st;
392
+ }',
393
+ 'int BN_set_word(BIGNUM * a, BN_ULONG w) {
394
+ bn_check_top(a);
395
+ if (bn_expand(a, (int) sizeof(BN_ULONG) * 8) == NULL) return (0);
396
+ a -> neg = 0;
397
+ a -> d[0] = w;
398
+ a -> top = (w ? 1 : 0);
399
+ bn_check_top(a);
400
+ return (1);
401
+ }',
402
+ 'static ossl_inline BIGNUM * bn_expand(BIGNUM * a, int bits) {
403
+ if (bits > (INT_MAX - BN_BITS2 + 1)) return NULL;
404
+ if (((bits + BN_BITS2 - 1) / BN_BITS2) <= (a) -> dmax) return a;
405
+ return bn_expand2((a), (bits + BN_BITS2 - 1) / BN_BITS2);
406
+ }',
407
+ 'int BN_mul(BIGNUM * r,
408
+ const BIGNUM * a,
409
+ const BIGNUM * b, BN_CTX * ctx) {
410
+ int ret = 0;
411
+ int top, al, bl;
412
+ BIGNUM * rr;
413
+ #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) int i;
414
+ #endif #ifdef BN_RECURSION BIGNUM * t = NULL;
415
+ int j = 0, k;
416
+ #endif bn_check_top(a);
417
+ bn_check_top(b);
418
+ bn_check_top(r);
419
+ al = a -> top;
420
+ bl = b -> top;
421
+ if ((al == 0) || (bl == 0)) {
422
+ BN_zero(r);
423
+ return (1);
424
+ }
425
+ top = al + bl;
426
+ BN_CTX_start(ctx);
427
+ if ((r == a) || (r == b)) {
428
+ if ((rr = BN_CTX_get(ctx)) == NULL) goto err;
429
+ } else rr = r;
430
+ rr -> neg = a -> neg ^ b -> neg;
431
+ #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) i = al - bl;
432
+ #endif #ifdef BN_MUL_COMBA
433
+ if (i == 0) {
434
+ #
435
+ if 0
436
+ if (al == 4) {
437
+ if (bn_wexpand(rr, 8) == NULL) goto err;
438
+ rr -> top = 8;
439
+ bn_mul_comba4(rr -> d, a -> d, b -> d);
440
+ goto end;
441
+ }
442
+ # endif
443
+ if (al == 8) {
444
+ if (bn_wexpand(rr, 16) == NULL) goto err;
445
+ rr -> top = 16;
446
+ bn_mul_comba8(rr -> d, a -> d, b -> d);
447
+ goto end;
448
+ }
449
+ }
450
+ #endif #ifdef BN_RECURSION
451
+ if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {
452
+ if (i >= -1 && i <= 1) {
453
+ if (i >= 0) {
454
+ j = BN_num_bits_word((BN_ULONG) al);
455
+ }
456
+ if (i == -1) {
457
+ j = BN_num_bits_word((BN_ULONG) bl);
458
+ }
459
+ j = 1 << (j - 1);
460
+ assert(j <= al || j <= bl);
461
+ k = j + j;
462
+ t = BN_CTX_get(ctx);
463
+ if (t == NULL) goto err;
464
+ if (al > j || bl > j) {
465
+ if (bn_wexpand(t, k * 4) == NULL) goto err;
466
+ if (bn_wexpand(rr, k * 4) == NULL) goto err;
467
+ bn_mul_part_recursive(rr -> d, a -> d, b -> d, j, al - j, bl - j, t -> d);
468
+ } else {
469
+ if (bn_wexpand(t, k * 2) == NULL) goto err;
470
+ if (bn_wexpand(rr, k * 2) == NULL) goto err;
471
+ bn_mul_recursive(rr -> d, a -> d, b -> d, j, al - j, bl - j, t -> d);
472
+ }
473
+ rr -> top = top;
474
+ goto end;
475
+ }
476
+ #
477
+ if 0
478
+ if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {
479
+ BIGNUM * tmp_bn = (BIGNUM * ) b;
480
+ if (bn_wexpand(tmp_bn, al) == NULL) goto err;
481
+ tmp_bn -> d[bl] = 0;
482
+ bl++;
483
+ i--;
484
+ } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {
485
+ BIGNUM * tmp_bn = (BIGNUM * ) a;
486
+ if (bn_wexpand(tmp_bn, bl) == NULL) goto err;
487
+ tmp_bn -> d[al] = 0;
488
+ al++;
489
+ i++;
490
+ }
491
+ if (i == 0) {
492
+ j = BN_num_bits_word((BN_ULONG) al);
493
+ j = 1 << (j - 1);
494
+ k = j + j;
495
+ t = BN_CTX_get(ctx);
496
+ if (al == j) {
497
+ if (bn_wexpand(t, k * 2) == NULL) goto err;
498
+ if (bn_wexpand(rr, k * 2) == NULL) goto err;
499
+ bn_mul_recursive(rr -> d, a -> d, b -> d, al, t -> d);
500
+ } else {
501
+ if (bn_wexpand(t, k * 4) == NULL) goto err;
502
+ if (bn_wexpand(rr, k * 4) == NULL) goto err;
503
+ bn_mul_part_recursive(rr -> d, a -> d, b -> d, al - j, j, t -> d);
504
+ }
505
+ rr -> top = top;
506
+ goto end;
507
+ }
508
+ # endif
509
+ }
510
+ #endif
511
+ if (bn_wexpand(rr, top) == NULL) goto err;
512
+ rr -> top = top;
513
+ bn_mul_normal(rr -> d, a -> d, al, b -> d, bl);
514
+ #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) end: #endif bn_correct_top(rr);
515
+ if (r != rr && BN_copy(r, rr) == NULL) goto err;
516
+ ret = 1;
517
+ err: bn_check_top(r);
518
+ BN_CTX_end(ctx);
519
+ return (ret);
520
+ }',
521
+ 'void bn_mul_part_recursive(BN_ULONG * r, BN_ULONG * a, BN_ULONG * b, int n, int tna, int tnb, BN_ULONG * t) {
522
+ int i, j, n2 = n * 2;
523
+ int c1, c2, neg;
524
+ BN_ULONG ln, lo, * p;
525
+ if (n < 8) {
526
+ bn_mul_normal(r, a, n + tna, b, n + tnb);
527
+ return;
528
+ }
529
+ c1 = bn_cmp_part_words(a, & (a[n]), tna, n - tna);
530
+ c2 = bn_cmp_part_words( & (b[n]), b, tnb, tnb - n);
531
+ neg = 0;
532
+ switch (c1 * 3 + c2) {
533
+ case -4:
534
+ bn_sub_part_words(t, & (a[n]), a, tna, tna - n);
535
+ bn_sub_part_words( & (t[n]), b, & (b[n]), tnb, n - tnb);
536
+ break;
537
+ case -3:
538
+ case -2:
539
+ bn_sub_part_words(t, & (a[n]), a, tna, tna - n);
540
+ bn_sub_part_words( & (t[n]), & (b[n]), b, tnb, tnb - n);
541
+ neg = 1;
542
+ break;
543
+ case -1:
544
+ case 0:
545
+ case 1:
546
+ case 2:
547
+ bn_sub_part_words(t, a, & (a[n]), tna, n - tna);
548
+ bn_sub_part_words( & (t[n]), b, & (b[n]), tnb, n - tnb);
549
+ neg = 1;
550
+ break;
551
+ case 3:
552
+ case 4:
553
+ bn_sub_part_words(t, a, & (a[n]), tna, n - tna);
554
+ bn_sub_part_words( & (t[n]), & (b[n]), b, tnb, tnb - n);
555
+ break;
556
+ }
557
+ #
558
+ if 0
559
+ if (n == 4) {
560
+ bn_mul_comba4( & (t[n2]), t, & (t[n]));
561
+ bn_mul_comba4(r, a, b);
562
+ bn_mul_normal( & (r[n2]), & (a[n]), tn, & (b[n]), tn);
563
+ memset( & r[n2 + tn * 2], 0, sizeof( * r) * (n2 - tn * 2));
564
+ } else # endif
565
+ if (n == 8) {
566
+ bn_mul_comba8( & (t[n2]), t, & (t[n]));
567
+ bn_mul_comba8(r, a, b);
568
+ bn_mul_normal( & (r[n2]), & (a[n]), tna, & (b[n]), tnb);
569
+ memset( & r[n2 + tna + tnb], 0, sizeof( * r) * (n2 - tna - tnb));
570
+ } else {
571
+ p = & (t[n2 * 2]);
572
+ bn_mul_recursive( & (t[n2]), t, & (t[n]), n, 0, 0, p);
573
+ bn_mul_recursive(r, a, b, n, 0, 0, p);
574
+ i = n / 2;
575
+ if (tna > tnb) j = tna - i;
576
+ else j = tnb - i;
577
+ if (j == 0) {
578
+ bn_mul_recursive( & (r[n2]), & (a[n]), & (b[n]), i, tna - i, tnb - i, p);
579
+ memset( & r[n2 + i * 2], 0, sizeof( * r) * (n2 - i * 2));
580
+ } else if (j > 0) {
581
+ bn_mul_part_recursive( & (r[n2]), & (a[n]), & (b[n]), i, tna - i, tnb - i, p);
582
+ memset( & (r[n2 + tna + tnb]), 0, sizeof(BN_ULONG) * (n2 - tna - tnb));
583
+ } else {
584
+ memset( & r[n2], 0, sizeof( * r) * n2);
585
+ if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {
586
+ bn_mul_normal( & (r[n2]), & (a[n]), tna, & (b[n]), tnb);
587
+ } else {
588
+ for (;;) {
589
+ i /= 2;
590
+ if (i < tna || i < tnb) {
591
+ bn_mul_part_recursive( & (r[n2]), & (a[n]), & (b[n]), i, tna - i, tnb - i, p);
592
+ break;
593
+ } else if (i == tna || i == tnb) {
594
+ bn_mul_recursive( & (r[n2]), & (a[n]), & (b[n]), i, tna - i, tnb - i, p);
595
+ break;
596
+ }
597
+ }
598
+ }
599
+ }
600
+ }
601
+ c1 = (int)(bn_add_words(t, r, & (r[n2]), n2));
602
+ if (neg) {
603
+ c1 -= (int)(bn_sub_words( & (t[n2]), t, & (t[n2]), n2));
604
+ } else {
605
+ c1 += (int)(bn_add_words( & (t[n2]), & (t[n2]), t, n2));
606
+ }
607
+ c1 += (int)(bn_add_words( & (r[n]), & (r[n]), & (t[n2]), n2));
608
+ if (c1) {
609
+ p = & (r[n + n2]);
610
+ lo = * p;
611
+ ln = (lo + c1) & BN_MASK2;* p = ln;
612
+ if (ln < (BN_ULONG) c1) {
613
+ do {
614
+ p++;
615
+ lo = * p;
616
+ ln = (lo + 1) & BN_MASK2;* p = ln;
617
+ } while (ln == 0);
618
+ }
619
+ }
620
+ }',
621
+ 'void bn_mul_normal(BN_ULONG * r, BN_ULONG * a, int na, BN_ULONG * b, int nb) {
622
+ BN_ULONG * rr;
623
+ if (na < nb) {
624
+ int itmp;
625
+ BN_ULONG * ltmp;
626
+ itmp = na;
627
+ na = nb;
628
+ nb = itmp;
629
+ ltmp = a;
630
+ a = b;
631
+ b = ltmp;
632
+ }
633
+ rr = & (r[na]);
634
+ if (nb <= 0) {
635
+ (void) bn_mul_words(r, a, na, 0);
636
+ return;
637
+ } else rr[0] = bn_mul_words(r, a, na, b[0]);
638
+ for (;;) {
639
+ if (--nb <= 0) return;
640
+ rr[1] = bn_mul_add_words( & (r[1]), a, na, b[1]);
641
+ if (--nb <= 0) return;
642
+ rr[2] = bn_mul_add_words( & (r[2]), a, na, b[2]);
643
+ if (--nb <= 0) return;
644
+ rr[3] = bn_mul_add_words( & (r[3]), a, na, b[3]);
645
+ if (--nb <= 0) return;
646
+ rr[4] = bn_mul_add_words( & (r[4]), a, na, b[4]);
647
+ rr += 4;
648
+ r += 4;
649
+ b += 4;
650
+ }
651
+ }'
652
+ ]
653
+ ```
654
+
655
+ [Leaderboard README](https://github.com/IBM/D2A/blob/main/leaderboard/README.md) || [Leaderboard page](https://ibm.github.io/D2A)