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

« back to all changes in this revision

Viewing changes to cipher/ac.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2009-02-21 13:46:58 UTC
  • mto: (1.1.6 upstream) (2.1.3 squeeze)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20090221134658-855twvcr4ezk2ron
ImportĀ upstreamĀ versionĀ 1.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* ac.c - Alternative interface for asymmetric cryptography.
2
2
   Copyright (C) 2003, 2004, 2005, 2006
3
 
                 2007  Free Software Foundation, Inc.
 
3
                 2007, 2008  Free Software Foundation, Inc.
4
4
 
5
5
   This file is part of Libgcrypt.
6
6
  
24
24
#include <string.h>
25
25
#include <stdio.h>
26
26
#include <stddef.h>
27
 
#include <assert.h>
28
27
 
29
28
#include "g10lib.h"
30
29
#include "cipher.h"
127
126
  gcry_ac_data_t data_new;
128
127
  gcry_error_t err;
129
128
 
 
129
  if (fips_mode ())
 
130
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
131
 
130
132
  data_new = gcry_malloc (sizeof (*data_new));
131
133
  if (! data_new)
132
134
    {
240
242
  gcry_ac_data_t data_new;
241
243
  gcry_error_t err;
242
244
 
 
245
  if (fips_mode ())
 
246
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
247
 
243
248
  /* Allocate data set.  */
244
249
  data_new = gcry_malloc (sizeof (*data_new));
245
250
  if (! data_new)
290
295
  name_cp = NULL;
291
296
  mpi_cp = NULL;
292
297
 
 
298
  if (fips_mode ())
 
299
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
300
 
293
301
  if (flags & ~(GCRY_AC_FLAG_DEALLOC | GCRY_AC_FLAG_COPY))
294
302
    {
295
303
      err = gcry_error (GPG_ERR_INV_ARG);
370
378
  gcry_error_t err;
371
379
  unsigned int i;
372
380
 
 
381
  if (fips_mode ())
 
382
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
383
 
373
384
  if (flags & ~(GCRY_AC_FLAG_COPY))
374
385
    {
375
386
      err = gcry_error (GPG_ERR_INV_ARG);
421
432
  name_cp = NULL;
422
433
  mpi_cp = NULL;
423
434
 
 
435
  if (fips_mode ())
 
436
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
437
 
424
438
  if (flags & ~(GCRY_AC_FLAG_COPY))
425
439
    {
426
440
      err = gcry_error (GPG_ERR_INV_ARG);
496
510
  arg_list = NULL;
497
511
  err = 0;
498
512
 
 
513
  if (fips_mode ())
 
514
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
515
 
499
516
  /* Calculate size of S-expression representation.  */
500
517
 
501
518
  i = 0;
626
643
  mpi = NULL;
627
644
  err = 0;
628
645
 
 
646
  if (fips_mode ())
 
647
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
648
 
629
649
  /* Process S-expression/identifiers.  */
630
650
 
631
651
  if (identifiers)
795
815
  if (! data)
796
816
    return;
797
817
 
 
818
  if (fips_mode ())
 
819
    return;
 
820
 
798
821
  mpi_buffer = NULL;
799
822
 
800
823
  data_n = _gcry_ac_data_length (data);
859
882
{
860
883
  memset (ac_io, 0, sizeof (*ac_io));
861
884
 
862
 
  assert ((mode == GCRY_AC_IO_READABLE) || (mode == GCRY_AC_IO_WRITABLE));
863
 
  assert ((type == GCRY_AC_IO_STRING) || (type == GCRY_AC_IO_STRING));
 
885
  if (fips_mode ())
 
886
    return;
 
887
 
 
888
  gcry_assert ((mode == GCRY_AC_IO_READABLE) || (mode == GCRY_AC_IO_WRITABLE));
 
889
  gcry_assert ((type == GCRY_AC_IO_STRING) || (type == GCRY_AC_IO_STRING));
864
890
 
865
891
  ac_io->mode = mode;
866
892
  ac_io->type = type;
920
946
{
921
947
  gcry_error_t err;
922
948
 
923
 
  assert (ac_io->mode == GCRY_AC_IO_WRITABLE);
 
949
  gcry_assert (ac_io->mode == GCRY_AC_IO_WRITABLE);
924
950
  err = 0;
925
951
 
926
952
  switch (ac_io->type)
980
1006
{
981
1007
  gcry_error_t err;
982
1008
  
983
 
  assert (ac_io->mode == GCRY_AC_IO_READABLE);
 
1009
  gcry_assert (ac_io->mode == GCRY_AC_IO_READABLE);
984
1010
  err = 0;
985
1011
 
986
1012
  switch (ac_io->type)
1362
1388
  *handle = NULL;
1363
1389
  module = NULL;
1364
1390
 
 
1391
  if (fips_mode ())
 
1392
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
1393
 
1365
1394
  /* Get name.  */
1366
1395
  algorithm_name = _gcry_pk_aliased_algo_name (algorithm);
1367
1396
  if (! algorithm_name)
1431
1460
 
1432
1461
  (void)handle;
1433
1462
 
 
1463
  if (fips_mode ())
 
1464
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
1465
 
1434
1466
  /* Allocate.  */
1435
1467
  key_new = gcry_malloc (sizeof (*key_new));
1436
1468
  if (! key_new)
1488
1520
 
1489
1521
  (void)misc_data;
1490
1522
 
 
1523
  if (fips_mode ())
 
1524
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
1525
 
1491
1526
  key_data_secret = NULL;
1492
1527
  key_data_public = NULL;
1493
1528
  key_secret = NULL;
1496
1531
  arg_list = NULL;
1497
1532
  genkey_sexp_request = NULL;
1498
1533
  genkey_sexp_reply = NULL;
 
1534
  key_sexp = NULL;
1499
1535
 
1500
1536
  /* Allocate key pair.  */
1501
1537
  key_pair_new = gcry_malloc (sizeof (struct gcry_ac_key_pair));
1631
1667
  gcry_free (arg_list);
1632
1668
  gcry_sexp_release (genkey_sexp_request);
1633
1669
  gcry_sexp_release (genkey_sexp_reply);
 
1670
  gcry_sexp_release (key_sexp);
1634
1671
  if (err)
1635
1672
    {
1636
1673
      _gcry_ac_data_destroy (key_data_secret);
1650
1687
{
1651
1688
  gcry_ac_key_t key;
1652
1689
 
 
1690
  if (fips_mode ())
 
1691
    return NULL;
 
1692
 
1653
1693
  switch (which)
1654
1694
    {
1655
1695
    case GCRY_AC_KEY_SECRET:
1679
1719
      if (key->data)
1680
1720
        {
1681
1721
          for (i = 0; i < key->data->data_n; i++)
1682
 
            if (key->data->data[i].mpi != NULL)
1683
 
              gcry_mpi_release (key->data->data[i].mpi);
 
1722
            {
 
1723
              if (key->data->data[i].mpi)
 
1724
                gcry_mpi_release (key->data->data[i].mpi);
 
1725
              if (key->data->data[i].name)
 
1726
                gcry_free (key->data->data[i].name);
 
1727
            }
 
1728
          gcry_free (key->data->data);
1684
1729
          gcry_free (key->data);
1685
1730
        }
1686
1731
      gcry_free (key);
1703
1748
gcry_ac_data_t
1704
1749
_gcry_ac_key_data_get (gcry_ac_key_t key)
1705
1750
{
 
1751
  if (fips_mode ())
 
1752
    return NULL;
1706
1753
  return key->data;
1707
1754
}
1708
1755
 
1713
1760
  gcry_sexp_t key_sexp;
1714
1761
  gcry_error_t err;
1715
1762
 
 
1763
  if (fips_mode ())
 
1764
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
1765
 
1716
1766
  key_sexp = NULL;
1717
1767
  err = ac_data_construct (ac_key_identifiers[key->type], 0, 0,
1718
1768
                           handle->algorithm_name, key->data, &key_sexp);
1737
1787
  gcry_error_t err;
1738
1788
  unsigned int n;
1739
1789
 
 
1790
  if (fips_mode ())
 
1791
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
1792
 
1740
1793
  key_sexp = NULL;
1741
1794
 
1742
1795
  err = ac_data_construct (ac_key_identifiers[key->type],
1770
1823
  gcry_error_t err;
1771
1824
  unsigned char *ret;
1772
1825
 
 
1826
  if (fips_mode ())
 
1827
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
1828
 
1773
1829
  key_sexp = NULL;
1774
1830
  err = ac_data_construct (ac_key_identifiers[key->type], 0, 0,
1775
1831
                           handle->algorithm_name, key->data, &key_sexp);
1816
1872
  gcry_sexp_t sexp_key;
1817
1873
  gcry_error_t err;
1818
1874
 
 
1875
  if (fips_mode ())
 
1876
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
1877
 
1819
1878
  data_encrypted_new = NULL;
1820
1879
  sexp_request = NULL;
1821
1880
  sexp_reply = NULL;
1890
1949
  gcry_sexp_t sexp_key;
1891
1950
  gcry_error_t err;
1892
1951
 
 
1952
  if (fips_mode ())
 
1953
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
1954
 
1893
1955
  sexp_request = NULL;
1894
1956
  sexp_reply = NULL;
1895
1957
  sexp_value = NULL;
1962
2024
  gcry_sexp_t sexp_key;
1963
2025
  gcry_error_t err;
1964
2026
 
 
2027
  if (fips_mode ())
 
2028
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
2029
 
1965
2030
  data_signed = NULL;
1966
2031
  data_value = NULL;
1967
2032
  sexp_request = NULL;
2032
2097
  gcry_sexp_t sexp_key;
2033
2098
  gcry_error_t err;
2034
2099
 
 
2100
  if (fips_mode ())
 
2101
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
2102
 
2035
2103
  sexp_signature = NULL;
2036
2104
  data_value = NULL;
2037
2105
  sexp_data = NULL;
2502
2570
                      gcry_ac_io_t *ac_io_read,
2503
2571
                      gcry_ac_io_t *ac_io_write)
2504
2572
{
 
2573
  if (fips_mode ())
 
2574
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
2575
 
2505
2576
  return ac_data_dencode (method, DATA_ENCODE, flags, options,
2506
2577
                          ac_io_read, ac_io_write);
2507
2578
}
2515
2586
                      gcry_ac_io_t *ac_io_read,
2516
2587
                      gcry_ac_io_t *ac_io_write)
2517
2588
{
 
2589
  if (fips_mode ())
 
2590
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
2591
 
2518
2592
  return ac_data_dencode (method, DATA_DECODE, flags, options,
2519
2593
                          ac_io_read, ac_io_write);
2520
2594
}
2530
2604
  gcry_mpi_t m;
2531
2605
  gcry_mpi_t d;
2532
2606
 
 
2607
  if (fips_mode ())
 
2608
    return;
 
2609
 
2533
2610
  base = gcry_mpi_new (0);
2534
2611
  gcry_mpi_set_ui (base, 256);
2535
2612
 
2568
2645
  gcry_error_t err;
2569
2646
  unsigned int nbits;
2570
2647
 
 
2648
  if (fips_mode ())
 
2649
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
2650
 
2571
2651
  nbits = gcry_mpi_get_nbits (mpi);
2572
2652
  buffer_n = (nbits + 7) / 8;
2573
2653
  buffer = gcry_malloc (buffer_n);
2597
2677
  gcry_mpi_t x;
2598
2678
  gcry_mpi_t a;
2599
2679
  
 
2680
  if (fips_mode ())
 
2681
    return;
 
2682
 
2600
2683
  a = gcry_mpi_new (0);
2601
2684
  gcry_mpi_set_ui (a, 1);
2602
2685
  x = gcry_mpi_new (0);
2815
2898
 
2816
2899
  (void)flags;
2817
2900
 
 
2901
  if (fips_mode ())
 
2902
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
2903
 
2818
2904
  data_encrypted = NULL;
2819
2905
  mpi_encrypted = NULL;
2820
2906
  mpi_plain = NULL;
2906
2992
 
2907
2993
  (void)flags;
2908
2994
 
 
2995
  if (fips_mode ())
 
2996
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
2997
 
2909
2998
  data_encrypted = NULL;
2910
2999
  mpi_encrypted = NULL;
2911
3000
  mpi_decrypted = NULL;
3017
3106
 
3018
3107
  (void)flags;
3019
3108
 
 
3109
  if (fips_mode ())
 
3110
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
3111
 
3020
3112
  data_signed = NULL;
3021
3113
  mpi_signed = NULL;
3022
3114
  opts_em = NULL;
3109
3201
 
3110
3202
  (void)flags;
3111
3203
 
 
3204
  if (fips_mode ())
 
3205
    return gpg_error (GPG_ERR_NOT_SUPPORTED);
 
3206
 
3112
3207
  mpi_signature = NULL;
3113
3208
  elements_sig = NULL;
3114
3209
  data_signed = NULL;
3199
3294
gcry_err_code_t
3200
3295
_gcry_ac_init (void)
3201
3296
{
 
3297
  if (fips_mode ())
 
3298
    return GPG_ERR_NOT_SUPPORTED;
 
3299
 
3202
3300
  return 0;
3203
3301
}