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

« back to all changes in this revision

Viewing changes to cipher/sha1.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:
40
40
#include "memory.h"
41
41
#include "bithelp.h"
42
42
#include "cipher.h"
 
43
#include "hash-common.h"
43
44
 
44
45
 
45
46
/* A macro to test whether P is properly aligned for an u32 type.
373
374
}
374
375
 
375
376
 
 
377
 
 
378
/* 
 
379
     Self-test section.
 
380
 */
 
381
 
 
382
 
 
383
static gpg_err_code_t
 
384
selftests_sha1 (int extended, selftest_report_func_t report)
 
385
{
 
386
  const char *what;
 
387
  const char *errtxt;
 
388
  
 
389
  what = "short string";
 
390
  errtxt = _gcry_hash_selftest_check_one
 
391
    (GCRY_MD_SHA1, 0, 
 
392
     "abc", 3,
 
393
     "\xA9\x99\x3E\x36\x47\x06\x81\x6A\xBA\x3E"
 
394
     "\x25\x71\x78\x50\xC2\x6C\x9C\xD0\xD8\x9D", 20);
 
395
  if (errtxt)
 
396
    goto failed;
 
397
 
 
398
  if (extended)
 
399
    {
 
400
      what = "long string";
 
401
      errtxt = _gcry_hash_selftest_check_one
 
402
        (GCRY_MD_SHA1, 0, 
 
403
         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56,
 
404
         "\x84\x98\x3E\x44\x1C\x3B\xD2\x6E\xBA\xAE"
 
405
         "\x4A\xA1\xF9\x51\x29\xE5\xE5\x46\x70\xF1", 20);
 
406
      if (errtxt)
 
407
        goto failed;
 
408
      
 
409
      what = "one million \"a\"";
 
410
      errtxt = _gcry_hash_selftest_check_one
 
411
        (GCRY_MD_SHA1, 1,
 
412
         NULL, 0,
 
413
         "\x34\xAA\x97\x3C\xD4\xC4\xDA\xA4\xF6\x1E"
 
414
         "\xEB\x2B\xDB\xAD\x27\x31\x65\x34\x01\x6F", 20);
 
415
      if (errtxt)
 
416
        goto failed;
 
417
    }
 
418
 
 
419
  return 0; /* Succeeded. */
 
420
 
 
421
 failed:
 
422
  if (report)
 
423
    report ("digest", GCRY_MD_SHA1, what, errtxt);
 
424
  return GPG_ERR_SELFTEST_FAILED;
 
425
}
 
426
 
 
427
 
 
428
/* Run a full self-test for ALGO and return 0 on success.  */
 
429
static gpg_err_code_t
 
430
run_selftests (int algo, int extended, selftest_report_func_t report)
 
431
{
 
432
  gpg_err_code_t ec;
 
433
 
 
434
  switch (algo)
 
435
    {
 
436
    case GCRY_MD_SHA1:
 
437
      ec = selftests_sha1 (extended, report);
 
438
      break;
 
439
    default:
 
440
      ec = GPG_ERR_DIGEST_ALGO;
 
441
      break;
 
442
        
 
443
    }
 
444
  return ec;
 
445
}
 
446
 
 
447
 
 
448
 
 
449
 
376
450
static unsigned char asn[15] = /* Object ID is 1.3.14.3.2.26 */
377
451
  { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
378
452
    0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
398
472
    sha1_init, sha1_write, sha1_final, sha1_read,
399
473
    sizeof (SHA1_CONTEXT)
400
474
  };
 
475
md_extra_spec_t _gcry_digest_extraspec_sha1 = 
 
476
  {
 
477
    run_selftests
 
478
  };
 
479