summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2022-06-25 13:57:17 +0000
committerjsing <>2022-06-25 13:57:17 +0000
commitf3be0e605bb315d9af376aa2c6a9729a3a8db06c (patch)
tree92dc36f339a704f5104320dee464d02f9dd25baf /src
parent5d91c6409c12bb586d296afd1075bec7c2f2a203 (diff)
downloadopenbsd-f3be0e605bb315d9af376aa2c6a9729a3a8db06c.tar.gz
openbsd-f3be0e605bb315d9af376aa2c6a9729a3a8db06c.tar.bz2
openbsd-f3be0e605bb315d9af376aa2c6a9729a3a8db06c.zip
Add regress for ASN1_INTEGER_cmp()
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/asn1/asn1basic.c77
1 files changed, 76 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/asn1/asn1basic.c b/src/regress/lib/libcrypto/asn1/asn1basic.c
index 6c7e32df6c..543ee93ee8 100644
--- a/src/regress/lib/libcrypto/asn1/asn1basic.c
+++ b/src/regress/lib/libcrypto/asn1/asn1basic.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1basic.c,v 1.6 2022/04/27 17:43:06 jsing Exp $ */ 1/* $OpenBSD: asn1basic.c,v 1.7 2022/06/25 13:57:17 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -460,6 +460,79 @@ asn1_integer_decode_test(struct asn1_integer_test *ait)
460} 460}
461 461
462static int 462static int
463asn1_integer_cmp_test(void)
464{
465 ASN1_INTEGER *a = NULL, *b = NULL;
466 int failed = 1;
467
468 if ((a = ASN1_INTEGER_new()) == NULL)
469 goto failed;
470 if ((b = ASN1_INTEGER_new()) == NULL)
471 goto failed;
472
473 if (ASN1_INTEGER_cmp(a, b) != 0) {
474 fprintf(stderr, "FAIL: INTEGER 0 == 0");
475 goto failed;
476 }
477
478 if (!ASN1_INTEGER_set(b, 1)) {
479 fprintf(stderr, "FAIL: failed to set INTEGER");
480 goto failed;
481 }
482 if (ASN1_INTEGER_cmp(a, b) >= 0) {
483 fprintf(stderr, "FAIL: INTEGER 0 < 1");
484 goto failed;
485 }
486 if (ASN1_INTEGER_cmp(b, a) <= 0) {
487 fprintf(stderr, "FAIL: INTEGER 1 > 0");
488 goto failed;
489 }
490
491 if (!ASN1_INTEGER_set(b, -1)) {
492 fprintf(stderr, "FAIL: failed to set INTEGER");
493 goto failed;
494 }
495 if (ASN1_INTEGER_cmp(a, b) <= 0) {
496 fprintf(stderr, "FAIL: INTEGER 0 > -1");
497 goto failed;
498 }
499 if (ASN1_INTEGER_cmp(b, a) >= 0) {
500 fprintf(stderr, "FAIL: INTEGER -1 < 0");
501 goto failed;
502 }
503
504 if (!ASN1_INTEGER_set(a, 1)) {
505 fprintf(stderr, "FAIL: failed to set INTEGER");
506 goto failed;
507 }
508 if (ASN1_INTEGER_cmp(a, b) <= 0) {
509 fprintf(stderr, "FAIL: INTEGER 1 > -1");
510 goto failed;
511 }
512 if (ASN1_INTEGER_cmp(b, a) >= 0) {
513 fprintf(stderr, "FAIL: INTEGER -1 < 1");
514 goto failed;
515 }
516
517 if (!ASN1_INTEGER_set(b, 1)) {
518 fprintf(stderr, "FAIL: failed to set INTEGER");
519 goto failed;
520 }
521 if (ASN1_INTEGER_cmp(a, b) != 0) {
522 fprintf(stderr, "FAIL: INTEGER 1 == 1");
523 goto failed;
524 }
525
526 failed = 0;
527
528 failed:
529 ASN1_INTEGER_free(a);
530 ASN1_INTEGER_free(b);
531
532 return failed;
533}
534
535static int
463asn1_integer_test(void) 536asn1_integer_test(void)
464{ 537{
465 struct asn1_integer_test *ait; 538 struct asn1_integer_test *ait;
@@ -475,6 +548,8 @@ asn1_integer_test(void)
475 failed |= asn1_integer_decode_test(ait); 548 failed |= asn1_integer_decode_test(ait);
476 } 549 }
477 550
551 failed |= asn1_integer_cmp_test();
552
478 return failed; 553 return failed;
479} 554}
480 555