Lines Matching defs:cipher

0 /* cipher.c  -	cipher dispatcher
28 #include "cipher.h"
50 gcry_cipher_spec_t *cipher;
163 gcry_cipher_spec_t *cipher;
173 API) we need to keep these function pointers here. The cipher
209 /* What follows are two contexts of the cipher in use. The first
210 one needs to be aligned well enough for the cipher operation
220 /* These dummy functions are used in case a cipher implementation
287 for (i = 0; !err && cipher_table[i].cipher; i++)
289 if (! cipher_table[i].cipher->setkey)
290 cipher_table[i].cipher->setkey = dummy_setkey;
291 if (! cipher_table[i].cipher->encrypt)
292 cipher_table[i].cipher->encrypt = dummy_encrypt_block;
293 if (! cipher_table[i].cipher->decrypt)
294 cipher_table[i].cipher->decrypt = dummy_decrypt_block;
295 if (! cipher_table[i].cipher->stencrypt)
296 cipher_table[i].cipher->stencrypt = dummy_encrypt_stream;
297 if (! cipher_table[i].cipher->stdecrypt)
298 cipher_table[i].cipher->stdecrypt = dummy_decrypt_stream;
305 (void *) cipher_table[i].cipher,
318 gcry_cipher_spec_t *cipher = (gcry_cipher_spec_t *) spec;
320 const char **aliases = cipher->aliases;
321 int i, ret = ! stricmp (name, cipher->name);
334 gcry_cipher_spec_t *cipher = (gcry_cipher_spec_t *) spec;
336 gcry_cipher_oid_spec_t *oid_specs = cipher->oids;
347 /* Internal function. Lookup a cipher entry by it's name. */
351 gcry_module_t cipher;
353 cipher = _gcry_module_lookup (ciphers_registered, (void *) name,
356 return cipher;
359 /* Internal function. Lookup a cipher entry by it's oid. */
363 gcry_module_t cipher;
365 cipher = _gcry_module_lookup (ciphers_registered, (void *) oid,
368 return cipher;
371 /* Register a new cipher module whose specification can be found in
375 _gcry_cipher_register (gcry_cipher_spec_t *cipher,
389 (void *)cipher,
403 /* Unregister the cipher identified by MODULE, which must have been
433 gcry_cipher_spec_t *cipher = module->spec;
436 for (i = 0; cipher->oids[i].oid && !ret; i++)
437 if (! stricmp (oid, cipher->oids[i].oid))
442 *oid_spec = cipher->oids[i];
451 /* Map STRING to the cipher algorithm identifier. Returns the
452 algorithm ID of the cipher for the given name or 0 if the name is
458 gcry_module_t cipher;
475 cipher = gcry_cipher_lookup_name (string);
476 if (cipher)
478 algorithm = cipher->mod_id;
479 _gcry_module_release (cipher);
490 function returns the cipher mode (GCRY_CIPHER_MODE_*) associated
512 /* Map the cipher algorithm whose ID is contained in ALGORITHM to a
518 gcry_module_t cipher;
524 cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
525 if (cipher)
527 name = ((gcry_cipher_spec_t *) cipher->spec)->name;
528 _gcry_module_release (cipher);
537 /* Map the cipher algorithm identifier ALGORITHM to a string
548 /* Flag the cipher algorithm with the identifier ALGORITHM as
555 gcry_module_t cipher;
560 cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
561 if (cipher)
563 if (! (cipher->flags & FLAG_MODULE_DISABLED))
564 cipher->flags |= FLAG_MODULE_DISABLED;
565 _gcry_module_release (cipher);
571 /* Return 0 if the cipher algorithm with identifier ALGORITHM is
578 gcry_module_t cipher;
583 cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
584 if (cipher)
586 if (cipher->flags & FLAG_MODULE_DISABLED)
588 _gcry_module_release (cipher);
598 /* Return the standard length of the key for the cipher algorithm with
605 gcry_module_t cipher;
611 cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
612 if (cipher)
614 len = ((gcry_cipher_spec_t *) cipher->spec)->keylen;
616 log_bug ("cipher %d w/o key length\n", algorithm);
617 _gcry_module_release (cipher);
620 log_bug ("cipher %d not found\n", algorithm);
626 /* Return the block length of the cipher algorithm with the identifier
633 gcry_module_t cipher;
639 cipher = _gcry_module_lookup_id (ciphers_registered, algorithm);
640 if (cipher)
642 len = ((gcry_cipher_spec_t *) cipher->spec)->blocksize;
644 log_bug ("cipher %d w/o blocksize\n", algorithm);
645 _gcry_module_release (cipher);
648 log_bug ("cipher %d not found\n", algorithm);
656 Open a cipher handle for use with cipher algorithm ALGORITHM, using
657 the cipher mode MODE (one of the GCRY_CIPHER_MODE_*) and return a
674 gcry_cipher_spec_t *cipher = NULL;
686 /* Fetch the according module and check wether the cipher is marked
702 cipher = (gcry_cipher_spec_t *) module->spec;
729 if ((cipher->encrypt == dummy_encrypt_block)
730 || (cipher->decrypt == dummy_decrypt_block))
735 if ((cipher->stencrypt == dummy_encrypt_stream)
736 || (cipher->stdecrypt == dummy_decrypt_stream))
761 + 2 * cipher->contextsize
792 h->cipher = cipher;
838 /* Release all resources associated with the cipher handle H. H may be
880 ret = (*c->cipher->setkey) (&c->context.c, key, keylen);
884 memcpy ((void *) ((char *) &c->context.c + c->cipher->contextsize),
886 c->cipher->contextsize);
898 memset (c->u_iv.iv, 0, c->cipher->blocksize);
901 if (ivlen != c->cipher->blocksize)
904 ivlen, (unsigned int)c->cipher->blocksize);
907 if (ivlen > c->cipher->blocksize)
908 ivlen = c->cipher->blocksize;
915 /* Reset the cipher context to the initial context. This is basically
921 (char *) &c->context.c + c->cipher->contextsize,
922 c->cipher->contextsize);
923 memset (c->u_iv.iv, 0, c->cipher->blocksize);
924 memset (c->lastiv, 0, c->cipher->blocksize);
925 memset (c->ctr, 0, c->cipher->blocksize);
937 c->cipher->encrypt ( &c->context.c, outbuf, (byte*)/*arggg*/inbuf );
938 inbuf += c->cipher->blocksize;
939 outbuf += c->cipher->blocksize;
951 c->cipher->decrypt ( &c->context.c, outbuf, (byte*)/*arggg*/inbuf );
952 inbuf += c->cipher->blocksize;
953 outbuf += c->cipher->blocksize;
965 size_t blocksize = c->cipher->blocksize;
988 c->cipher->encrypt ( &c->context.c, outbuf, outbuf );
1018 c->cipher->encrypt (&c->context.c, outbuf, outbuf);
1031 size_t blocksize = c->cipher->blocksize;
1056 c->cipher->decrypt ( &c->context.c, outbuf, inbuf );
1060 inbuf += c->cipher->blocksize;
1061 outbuf += c->cipher->blocksize;
1077 c->cipher->decrypt ( &c->context.c, outbuf, inbuf );
1084 c->cipher->decrypt (&c->context.c, outbuf, c->u_iv.iv);
1097 size_t blocksize = c->cipher->blocksize;
1104 for (ivp=c->u_iv.iv+c->cipher->blocksize - c->unused;
1136 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1149 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1159 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1176 size_t blocksize = c->cipher->blocksize;
1222 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1238 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1253 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1272 size_t blocksize = c->cipher->blocksize;
1278 for (ivp=c->u_iv.iv+c->cipher->blocksize - c->unused;
1298 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1307 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1320 size_t blocksize = c->cipher->blocksize;
1343 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1352 c->cipher->encrypt ( &c->context.c, c->u_iv.iv, c->u_iv.iv );
1371 if ((n % c->cipher->blocksize) == 0)
1373 c->cipher->encrypt (&c->context.c, tmp, c->ctr);
1375 for (i = c->cipher->blocksize; i > 0; i--)
1384 outbuf[n] = inbuf[n] ^ tmp[n % c->cipher->blocksize];
1409 if (!(nbytes%c->cipher->blocksize))
1410 do_ecb_encrypt(c, outbuf, inbuf, nbytes/c->cipher->blocksize );
1415 if (!(nbytes%c->cipher->blocksize)
1416 || (nbytes > c->cipher->blocksize
1432 c->cipher->stencrypt ( &c->context.c,
1438 fips_signal_error ("cipher mode NONE used");
1474 h->cipher->blocksize : inlen))
1479 && (inlen > h->cipher->blocksize)))))
1480 && (inlen % h->cipher->blocksize))
1508 if (!(nbytes%c->cipher->blocksize))
1509 do_ecb_decrypt(c, outbuf, inbuf, nbytes/c->cipher->blocksize );
1514 if (!(nbytes%c->cipher->blocksize)
1515 || (nbytes > c->cipher->blocksize
1531 c->cipher->stdecrypt ( &c->context.c,
1537 fips_signal_error ("cipher mode NONE used");
1573 && (inlen > h->cipher->blocksize)))))
1574 && (inlen % h->cipher->blocksize) != 0)
1594 c->u_iv.iv, c->cipher->blocksize - c->unused);
1596 c->lastiv + c->cipher->blocksize - c->unused, c->unused);
1622 if (ctr && ctrlen == hd->cipher->blocksize)
1623 memcpy (hd->ctr, ctr, hd->cipher->blocksize);
1625 memset (hd->ctr, 0, hd->cipher->blocksize);
1684 if (buffer && buflen == h->cipher->blocksize)
1685 memcpy (h->ctr, buffer, h->cipher->blocksize);
1687 memset (h->ctr, 0, h->cipher->blocksize);
1706 if (buflen < (1 + h->cipher->blocksize))
1715 n = h->cipher->blocksize;
1716 gcry_assert (n <= h->cipher->blocksize);
1718 ivp = h->u_iv.iv + h->cipher->blocksize - n;
1732 /* Return information about the cipher handle H. CMD is the kind of
1758 /* Return information about the given cipher algorithm ALGO.
1880 /* Get a list consisting of the IDs of the loaded cipher modules. If
1881 LIST is zero, write the number of loaded cipher modules to
1884 according size. In case there are less cipher modules than
1899 /* Run the selftests for cipher algorithm ALGO with optional reporting
1921 report ("cipher", algo, "module",