~ubuntu-branches/ubuntu/natty/libgcrypt11/natty-proposed

« back to all changes in this revision

Viewing changes to src/visibility.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2009-05-16 20:13:32 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090516201332-czkobpu32w318i16
Tags: 1.4.4-2ubuntu1
* Merge from Debian unstable (LP: #364535), remaining changes:
  - Add libgcrypt11-udeb for use by cryptsetup-udeb.
  - Add clean-la.mk, and add a symlink for the .la
  - Install to /lib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* visibility.c - Wrapper for all public functions.
2
 
 * Copyright (C) 2007  Free Software Foundation, Inc.
 
2
 * Copyright (C) 2007, 2008  Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of Libgcrypt.
5
5
 *
22
22
 
23
23
#define _GCRY_INCLUDED_BY_VISIBILITY_C 
24
24
#include "g10lib.h"
 
25
#include "cipher-proto.h"
 
26
 
25
27
 
26
28
 
27
29
const char *
455
457
  _gcry_mpi_rshift (x, a, n);
456
458
}
457
459
 
 
460
void
 
461
gcry_mpi_lshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n)
 
462
{
 
463
  _gcry_mpi_lshift (x, a, n);
 
464
}
 
465
 
458
466
gcry_mpi_t
459
467
gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits)
460
468
{
489
497
gcry_cipher_open (gcry_cipher_hd_t *handle,
490
498
                  int algo, int mode, unsigned int flags)
491
499
{
 
500
  if (!fips_is_operational ())
 
501
    {
 
502
      *handle = NULL;
 
503
      return gpg_error (fips_not_operational ());
 
504
    }
 
505
 
492
506
  return _gcry_cipher_open (handle, algo, mode, flags);
493
507
}
494
508
 
499
513
}
500
514
 
501
515
gcry_error_t
 
516
gcry_cipher_setkey (gcry_cipher_hd_t hd, const void *key, size_t keylen)
 
517
{
 
518
  if (!fips_is_operational ())
 
519
    return gpg_error (fips_not_operational ());
 
520
 
 
521
  return _gcry_cipher_setkey (hd, key, keylen);
 
522
}
 
523
 
 
524
gcry_error_t
 
525
gcry_cipher_setiv (gcry_cipher_hd_t hd, const void *iv, size_t ivlen)
 
526
{
 
527
  if (!fips_is_operational ())
 
528
    return gpg_error (fips_not_operational ());
 
529
 
 
530
  return _gcry_cipher_setiv (hd, iv, ivlen);
 
531
}
 
532
 
 
533
gpg_error_t
 
534
gcry_cipher_setctr (gcry_cipher_hd_t hd, const void *ctr, size_t ctrlen)
 
535
{
 
536
  if (!fips_is_operational ())
 
537
    return gpg_error (fips_not_operational ());
 
538
 
 
539
  return _gcry_cipher_setctr (hd, ctr, ctrlen);
 
540
}
 
541
 
 
542
 
 
543
gcry_error_t
502
544
gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer, size_t buflen)
503
545
{
 
546
  if (!fips_is_operational ())
 
547
    return gpg_error (fips_not_operational ());
 
548
 
504
549
  return _gcry_cipher_ctl (h, cmd, buffer, buflen);
505
550
}
506
551
 
513
558
gcry_error_t
514
559
gcry_cipher_algo_info (int algo, int what, void *buffer, size_t *nbytes)
515
560
{
 
561
  if (!fips_is_operational ())
 
562
    return gpg_error (fips_not_operational ());
 
563
 
516
564
  return _gcry_cipher_algo_info (algo, what, buffer, nbytes);
517
565
}
518
566
 
539
587
                     void *out, size_t outsize,
540
588
                     const void *in, size_t inlen)
541
589
{
 
590
  if (!fips_is_operational ())
 
591
    {
 
592
      /* Make sure that the plaintext will never make it to OUT. */
 
593
      if (out)
 
594
        memset (out, 0x42, outsize); 
 
595
      return gpg_error (fips_not_operational ());
 
596
    }
 
597
 
542
598
  return _gcry_cipher_encrypt (h, out, outsize, in, inlen);
543
599
}
544
600
 
547
603
                     void *out, size_t outsize,
548
604
                     const void *in, size_t inlen)
549
605
{
 
606
  if (!fips_is_operational ())
 
607
    return gpg_error (fips_not_operational ());
 
608
 
550
609
  return _gcry_cipher_decrypt (h, out, outsize, in, inlen);
551
 
 
552
610
}
553
611
 
554
612
size_t
572
630
gcry_error_t
573
631
gcry_pk_encrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t pkey)
574
632
{
 
633
  if (!fips_is_operational ())
 
634
    {
 
635
      *result = NULL;
 
636
      return gpg_error (fips_not_operational ());
 
637
    }
575
638
  return _gcry_pk_encrypt (result, data, pkey);
576
639
}
577
640
 
578
641
gcry_error_t
579
642
gcry_pk_decrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey)
580
643
{
 
644
  if (!fips_is_operational ())
 
645
    {
 
646
      *result = NULL;
 
647
      return gpg_error (fips_not_operational ());
 
648
    }
581
649
  return _gcry_pk_decrypt (result, data, skey);
582
650
}
583
651
 
584
652
gcry_error_t
585
653
gcry_pk_sign (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey)
586
654
{
 
655
  if (!fips_is_operational ())
 
656
    {
 
657
      *result = NULL;
 
658
      return gpg_error (fips_not_operational ());
 
659
    }
587
660
  return _gcry_pk_sign (result, data, skey);
588
661
}
589
662
 
590
663
gcry_error_t
591
664
gcry_pk_verify (gcry_sexp_t sigval, gcry_sexp_t data, gcry_sexp_t pkey)
592
665
{
 
666
  if (!fips_is_operational ())
 
667
    return gpg_error (fips_not_operational ());
593
668
  return _gcry_pk_verify (sigval, data, pkey);
594
669
}
595
670
 
596
671
gcry_error_t
597
672
gcry_pk_testkey (gcry_sexp_t key)
598
673
{
 
674
  if (!fips_is_operational ())
 
675
    return gpg_error (fips_not_operational ());
599
676
  return _gcry_pk_testkey (key);
600
677
}
601
678
 
602
679
gcry_error_t
603
680
gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms)
604
681
{
 
682
  if (!fips_is_operational ())
 
683
    {
 
684
      *r_key = NULL;
 
685
      return gpg_error (fips_not_operational ());
 
686
    }
605
687
  return _gcry_pk_genkey (r_key, s_parms);
606
688
}
607
689
 
614
696
gcry_error_t
615
697
gcry_pk_algo_info (int algo, int what, void *buffer, size_t *nbytes)
616
698
{
 
699
  if (!fips_is_operational ())
 
700
    return gpg_error (fips_not_operational ());
 
701
 
617
702
  return _gcry_pk_algo_info (algo, what, buffer, nbytes);
618
703
}
619
704
 
632
717
unsigned int
633
718
gcry_pk_get_nbits (gcry_sexp_t key)
634
719
{
 
720
  if (!fips_is_operational ())
 
721
    {
 
722
      (void)fips_not_operational ();
 
723
      return 0;
 
724
    }
 
725
 
635
726
  return _gcry_pk_get_nbits (key);
636
727
}
637
728
 
638
729
unsigned char *
639
730
gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array)
640
731
{
 
732
  if (!fips_is_operational ())
 
733
    {
 
734
      (void)fips_not_operational ();
 
735
      return NULL;
 
736
    }
641
737
  return _gcry_pk_get_keygrip (key, array);
642
738
}
643
739
 
650
746
gcry_error_t
651
747
gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags)
652
748
{
 
749
  if (!fips_is_operational ())
 
750
    {
 
751
      *h = NULL;
 
752
      return gpg_error (fips_not_operational ());
 
753
    }
 
754
 
653
755
  return _gcry_md_open (h, algo, flags);
654
756
}
655
757
 
662
764
gcry_error_t
663
765
gcry_md_enable (gcry_md_hd_t hd, int algo)
664
766
{
 
767
  if (!fips_is_operational ())
 
768
    return gpg_error (fips_not_operational ());
665
769
  return _gcry_md_enable (hd, algo);
666
770
}
667
771
 
668
772
gcry_error_t
669
773
gcry_md_copy (gcry_md_hd_t *bhd, gcry_md_hd_t ahd)
670
774
{
 
775
  if (!fips_is_operational ())
 
776
    {
 
777
      *bhd = NULL;
 
778
      return gpg_error (fips_not_operational ());
 
779
    }
671
780
  return _gcry_md_copy (bhd, ahd);
672
781
}
673
782
 
680
789
gcry_error_t
681
790
gcry_md_ctl (gcry_md_hd_t hd, int cmd, void *buffer, size_t buflen)
682
791
{
 
792
  if (!fips_is_operational ())
 
793
    return gpg_error (fips_not_operational ());
683
794
  return _gcry_md_ctl (hd, cmd, buffer, buflen);
684
795
}
685
796
 
686
797
void
687
798
gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length)
688
799
{
 
800
  if (!fips_is_operational ())
 
801
    {
 
802
      (void)fips_not_operational ();
 
803
      return;
 
804
    }
689
805
  _gcry_md_write (hd, buffer, length);
690
806
}
691
807
 
699
815
gcry_md_hash_buffer (int algo, void *digest,
700
816
                     const void *buffer, size_t length)
701
817
{
 
818
  if (!fips_is_operational ())
 
819
    {
 
820
      (void)fips_not_operational ();
 
821
      fips_signal_error ("called in non-operational state");
 
822
    }
702
823
  _gcry_md_hash_buffer (algo, digest, buffer, length);
703
824
}
704
825
 
705
826
int
706
827
gcry_md_get_algo (gcry_md_hd_t hd)
707
828
{
 
829
  if (!fips_is_operational ())
 
830
    {
 
831
      (void)fips_not_operational ();
 
832
      fips_signal_error ("used in non-operational state");
 
833
      return 0;
 
834
    }
708
835
  return _gcry_md_get_algo (hd);
709
836
}
710
837
 
717
844
int
718
845
gcry_md_is_enabled (gcry_md_hd_t a, int algo)
719
846
{
 
847
  if (!fips_is_operational ())
 
848
    {
 
849
      (void)fips_not_operational ();
 
850
      return 0;
 
851
    }
 
852
 
720
853
  return _gcry_md_is_enabled (a, algo);
721
854
}
722
855
 
729
862
gcry_error_t
730
863
gcry_md_info (gcry_md_hd_t h, int what, void *buffer, size_t *nbytes)
731
864
{
 
865
  if (!fips_is_operational ())
 
866
    return gpg_error (fips_not_operational ());
 
867
 
732
868
  return _gcry_md_info (h, what, buffer, nbytes);
733
869
}
734
870
 
753
889
gcry_error_t
754
890
gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen)
755
891
{
 
892
  if (!fips_is_operational ())
 
893
    return gpg_error (fips_not_operational ());
756
894
  return _gcry_md_setkey (hd, key, keylen);
757
895
}
758
896
 
1053
1191
void
1054
1192
gcry_randomize (void *buffer, size_t length, enum gcry_random_level level)
1055
1193
{
 
1194
  if (!fips_is_operational ())
 
1195
    {
 
1196
      (void)fips_not_operational ();
 
1197
      fips_signal_fatal_error ("called in non-operational state");
 
1198
      fips_noreturn (); 
 
1199
    }
1056
1200
  _gcry_randomize (buffer, length, level);
1057
1201
}
1058
1202
 
1059
1203
gcry_error_t
1060
1204
gcry_random_add_bytes (const void *buffer, size_t length, int quality)
1061
1205
{
 
1206
  if (!fips_is_operational ())
 
1207
    return gpg_error (fips_not_operational ());
1062
1208
  return _gcry_random_add_bytes (buffer, length, quality);
1063
1209
}
1064
1210
 
1065
1211
void *
1066
1212
gcry_random_bytes (size_t nbytes, enum gcry_random_level level)
1067
1213
{
 
1214
  if (!fips_is_operational ())
 
1215
    {
 
1216
      (void)fips_not_operational ();
 
1217
      fips_signal_fatal_error ("called in non-operational state");
 
1218
      fips_noreturn (); 
 
1219
    }
 
1220
 
1068
1221
  return _gcry_random_bytes (nbytes,level);
1069
1222
}
1070
1223
 
1071
1224
void *
1072
1225
gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level)
1073
1226
{
 
1227
  if (!fips_is_operational ())
 
1228
    {
 
1229
      (void)fips_not_operational ();
 
1230
      fips_signal_fatal_error ("called in non-operational state");
 
1231
      fips_noreturn (); 
 
1232
    }
 
1233
 
1074
1234
  return _gcry_random_bytes_secure (nbytes, level);
1075
1235
}
1076
1236
 
1084
1244
void
1085
1245
gcry_create_nonce (void *buffer, size_t length)
1086
1246
{
 
1247
  if (!fips_is_operational ())
 
1248
    {
 
1249
      (void)fips_not_operational ();
 
1250
      fips_signal_fatal_error ("called in non-operational state");
 
1251
      fips_noreturn (); 
 
1252
    }
1087
1253
  _gcry_create_nonce (buffer, length);
1088
1254
}
1089
1255
 
1251
1417
gcry_cipher_register (gcry_cipher_spec_t *cipher, int *algorithm_id,
1252
1418
                      gcry_module_t *module)
1253
1419
{
1254
 
  return _gcry_cipher_register (cipher, algorithm_id, module);
 
1420
  return _gcry_cipher_register (cipher, NULL, algorithm_id, module);
1255
1421
}
1256
1422
 
1257
1423
void
1264
1430
gcry_pk_register (gcry_pk_spec_t *pubkey, unsigned int *algorithm_id,
1265
1431
                  gcry_module_t *module)
1266
1432
{
1267
 
  return _gcry_pk_register (pubkey, algorithm_id, module);
 
1433
  return _gcry_pk_register (pubkey, NULL, algorithm_id, module);
1268
1434
}
1269
1435
 
1270
1436
void
1277
1443
gcry_md_register (gcry_md_spec_t *digest, unsigned int *algorithm_id,
1278
1444
                  gcry_module_t *module)
1279
1445
{
1280
 
  return _gcry_md_register (digest, algorithm_id, module);
 
1446
  return _gcry_md_register (digest, NULL, algorithm_id, module);
1281
1447
}
1282
1448
 
1283
1449
void