Fix API.
[shishi.git] / lib / authenticator.c
blob49fe494e3659dacaa0096a8e130c6f9d78dcab1c
1 /* authenticator.c functions for authenticators
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "internal.h"
24 /**
25 * shishi_authenticator:
26 * @handle: shishi handle as allocated by shishi_init().
28 * This function creates a new Authenticator, populated with some
29 * default values. It uses the current time as returned by the system
30 * for the ctime and cusec fields.
32 * Return value: Returns the authenticator or NULL on
33 * failure.
34 **/
35 Shishi_asn1
36 shishi_authenticator (Shishi * handle)
38 int res;
39 Shishi_asn1 node = NULL;
40 struct timeval tv;
41 struct timezone tz;
43 node = shishi_asn1_authenticator (handle);
44 if (!node)
45 return NULL;
47 res = shishi_asn1_write (handle, node, "authenticator-vno", "5", 0);
48 if (res != SHISHI_OK)
49 goto error;
51 res = shishi_authenticator_set_crealm (handle, node,
52 shishi_realm_default (handle));
53 if (res != SHISHI_OK)
54 goto error;
56 res = shishi_authenticator_client_set (handle, node,
57 shishi_principal_default (handle));
58 if (res != SHISHI_OK)
59 goto error;
61 gettimeofday (&tv, &tz);
62 res = shishi_authenticator_cusec_set (handle, node, tv.tv_usec % 1000000);
63 if (res != SHISHI_OK)
64 goto error;
66 res = shishi_asn1_write (handle, node, "ctime",
67 shishi_generalize_time (handle, time (NULL)), 0);
68 if (res != SHISHI_OK)
69 goto error;
71 res = shishi_asn1_write (handle, node, "seq-number", NULL, 0);
72 if (res != SHISHI_OK)
73 goto error;
75 return node;
77 error:
78 shishi_asn1_done (handle, node);
79 return NULL;
82 /**
83 * shishi_authenticator_subkey:
84 * @handle: shishi handle as allocated by shishi_init().
86 * This function creates a new Authenticator, populated with some
87 * default values. It uses the current time as returned by the system
88 * for the ctime and cusec fields. It adds a random subkey.
90 * Return value: Returns the authenticator or NULL on
91 * failure.
92 **/
93 Shishi_asn1
94 shishi_authenticator_subkey (Shishi * handle)
96 Shishi_asn1 node;
97 int res;
99 node = shishi_authenticator (handle);
100 if (node == NULL)
101 return NULL;
103 res = shishi_authenticator_add_random_subkey (handle, node);
104 if (res != SHISHI_OK)
105 return NULL;
107 return node;
111 * shishi_authenticator_print:
112 * @handle: shishi handle as allocated by shishi_init().
113 * @fh: file handle open for writing.
114 * @authenticator: authenticator as allocated by shishi_authenticator().
116 * Print ASCII armored DER encoding of authenticator to file.
118 * Return value: Returns SHISHI_OK iff successful.
121 shishi_authenticator_print (Shishi * handle,
122 FILE * fh, Shishi_asn1 authenticator)
124 return _shishi_print_armored_data (handle, fh, authenticator,
125 "Authenticator", NULL);
129 * shishi_authenticator_save:
130 * @handle: shishi handle as allocated by shishi_init().
131 * @fh: file handle open for writing.
132 * @authenticator: authenticator as allocated by shishi_authenticator().
134 * Save DER encoding of authenticator to file.
136 * Return value: Returns SHISHI_OK iff successful.
139 shishi_authenticator_save (Shishi * handle,
140 FILE * fh, Shishi_asn1 authenticator)
142 return _shishi_save_data (handle, fh, authenticator, "Authenticator");
146 * shishi_authenticator_to_file:
147 * @handle: shishi handle as allocated by shishi_init().
148 * @authenticator: Authenticator to save.
149 * @filetype: input variable specifying type of file to be written,
150 * see Shishi_filetype.
151 * @filename: input variable with filename to write to.
153 * Write Authenticator to file in specified TYPE. The file will be
154 * truncated if it exists.
156 * Return value: Returns SHISHI_OK iff successful.
159 shishi_authenticator_to_file (Shishi * handle, Shishi_asn1 authenticator,
160 int filetype, char *filename)
162 FILE *fh;
163 int res;
165 if (VERBOSE (handle))
166 printf (_("Writing Authenticator to %s...\n"), filename);
168 fh = fopen (filename, "w");
169 if (fh == NULL)
170 return SHISHI_FOPEN_ERROR;
172 if (VERBOSE (handle))
173 printf (_("Writing Authenticator in %s format...\n"),
174 filetype == SHISHI_FILETYPE_TEXT ? "TEXT" : "DER");
176 if (filetype == SHISHI_FILETYPE_TEXT)
177 res = shishi_authenticator_print (handle, fh, authenticator);
178 else
179 res = shishi_authenticator_save (handle, fh, authenticator);
180 if (res != SHISHI_OK)
181 return res;
183 res = fclose (fh);
184 if (res != 0)
185 return SHISHI_FCLOSE_ERROR;
187 if (VERBOSE (handle))
188 printf (_("Writing Authenticator to %s...done\n"), filename);
190 return SHISHI_OK;
194 * shishi_authenticator_parse:
195 * @handle: shishi handle as allocated by shishi_init().
196 * @fh: file handle open for reading.
197 * @authenticator: output variable with newly allocated authenticator.
199 * Read ASCII armored DER encoded authenticator from file and populate
200 * given authenticator variable.
202 * Return value: Returns SHISHI_OK iff successful.
205 shishi_authenticator_parse (Shishi * handle,
206 FILE * fh, Shishi_asn1 * authenticator)
208 return _shishi_authenticator_input (handle, fh, authenticator, 0);
212 * shishi_authenticator_read:
213 * @handle: shishi handle as allocated by shishi_init().
214 * @fh: file handle open for reading.
215 * @authenticator: output variable with newly allocated authenticator.
217 * Read DER encoded authenticator from file and populate given
218 * authenticator variable.
220 * Return value: Returns SHISHI_OK iff successful.
223 shishi_authenticator_read (Shishi * handle,
224 FILE * fh, Shishi_asn1 * authenticator)
226 return _shishi_authenticator_input (handle, fh, authenticator, 1);
230 * shishi_authenticator_from_file:
231 * @handle: shishi handle as allocated by shishi_init().
232 * @authenticator: output variable with newly allocated Authenticator.
233 * @filetype: input variable specifying type of file to be read,
234 * see Shishi_filetype.
235 * @filename: input variable with filename to read from.
237 * Read Authenticator from file in specified TYPE.
239 * Return value: Returns SHISHI_OK iff successful.
242 shishi_authenticator_from_file (Shishi * handle, Shishi_asn1 * authenticator,
243 int filetype, char *filename)
245 int res;
246 FILE *fh;
248 if (VERBOSE (handle))
249 printf (_("Reading Authenticator from %s...\n"), filename);
251 fh = fopen (filename, "r");
252 if (fh == NULL)
253 return SHISHI_FOPEN_ERROR;
255 if (VERBOSE (handle))
256 printf (_("Reading Authenticator in %s format...\n"),
257 filetype == SHISHI_FILETYPE_TEXT ? "TEXT" : "DER");
259 if (filetype == SHISHI_FILETYPE_TEXT)
260 res = shishi_authenticator_parse (handle, fh, authenticator);
261 else
262 res = shishi_authenticator_read (handle, fh, authenticator);
263 if (res != SHISHI_OK)
264 return res;
266 res = fclose (fh);
267 if (res != 0)
268 return SHISHI_FCLOSE_ERROR;
270 if (VERBOSE (handle))
271 printf (_("Reading Authenticator from %s...done\n"), filename);
273 return SHISHI_OK;
277 * shishi_authenticator_set_crealm:
278 * @handle: shishi handle as allocated by shishi_init().
279 * @authenticator: authenticator as allocated by shishi_authenticator().
280 * @crealm: input array with realm.
282 * Set realm field in authenticator to specified value.
284 * Return value: Returns SHISHI_OK iff successful.
287 shishi_authenticator_set_crealm (Shishi * handle,
288 Shishi_asn1 authenticator,
289 const char *crealm)
291 int res;
293 res = shishi_asn1_write (handle, authenticator, "crealm", crealm, 0);
294 if (res != SHISHI_OK)
295 return res;
297 return SHISHI_OK;
301 * shishi_authenticator_set_cname:
302 * @handle: shishi handle as allocated by shishi_init().
303 * @authenticator: authenticator as allocated by shishi_authenticator().
304 * @name_type: type of principial, see Shishi_name_type, usually
305 * SHISHI_NT_UNKNOWN.
306 * @cname: input array with principal name.
308 * Set principal field in authenticator to specified value.
310 * Return value: Returns SHISHI_OK iff successful.
313 shishi_authenticator_set_cname (Shishi * handle,
314 Shishi_asn1 authenticator,
315 Shishi_name_type name_type,
316 const char *cname[])
318 int res;
320 res = shishi_principal_name_set (handle, authenticator, "cname",
321 name_type, cname);
322 if (res != SHISHI_OK)
323 return res;
325 return SHISHI_OK;
329 * shishi_authenticator_client_set:
330 * @handle: shishi handle as allocated by shishi_init().
331 * @authenticator: Authenticator to set client name field in.
332 * @client: zero-terminated string with principal name on RFC 1964 form.
334 * Set the client name field in the Authenticator.
336 * Return value: Returns SHISHI_OK iff successful.
339 shishi_authenticator_client_set (Shishi * handle,
340 Shishi_asn1 authenticator,
341 const char *client)
343 int res;
345 res = shishi_principal_set (handle, authenticator, "cname", client);
346 if (res != SHISHI_OK)
347 return res;
349 return SHISHI_OK;
353 shishi_authenticator_ctime_get (Shishi * handle,
354 Shishi_asn1 authenticator, char *ctime)
356 int len;
357 int res;
359 len = GENERALIZEDTIME_TIME_LEN + 1;
360 res = shishi_asn1_read (handle, authenticator, "ctime", ctime, &len);
361 if (res == SHISHI_OK && len == GENERALIZEDTIME_TIME_LEN)
362 ctime[len] = '\0';
364 return res;
368 * shishi_authenticator_ctime_set:
369 * @handle: shishi handle as allocated by shishi_init().
370 * @authenticator: Authenticator as allocated by shishi_authenticator().
371 * @ctime: string with generalized time value to store in Authenticator.
373 * Store client time in Authenticator.
375 * Return value: Returns SHISHI_OK iff successful.
378 shishi_authenticator_ctime_set (Shishi * handle,
379 Shishi_asn1 authenticator, char *ctime)
381 int res;
383 res = shishi_asn1_write (handle, authenticator, "ctime",
384 ctime, GENERALIZEDTIME_TIME_LEN);
385 if (res != SHISHI_OK)
386 return res;
388 return SHISHI_OK;
392 * shishi_authenticator_cusec_get:
393 * @handle: shishi handle as allocated by shishi_init().
394 * @authenticator: Authenticator as allocated by shishi_authenticator().
395 * @cusec: output integer with client microseconds field.
397 * Extract client microseconds field from Authenticator.
399 * Return value: Returns SHISHI_OK iff successful.
402 shishi_authenticator_cusec_get (Shishi * handle,
403 Shishi_asn1 authenticator, int *cusec)
405 int res;
407 res = shishi_asn1_read_uint32 (handle, authenticator, "cusec", cusec);
408 if (res != SHISHI_OK)
409 return res;
411 return SHISHI_OK;
415 * shishi_authenticator_cusec_set:
416 * @handle: shishi handle as allocated by shishi_init().
417 * @authenticator: authenticator as allocated by shishi_authenticator().
418 * @cusec: client microseconds to set in authenticator, 0-999999.
420 * Set the cusec field in the Authenticator.
422 * Return value: Returns SHISHI_OK iff successful.
425 shishi_authenticator_cusec_set (Shishi * handle,
426 Shishi_asn1 authenticator, int cusec)
428 int res;
430 res = shishi_asn1_write_uint32 (handle, authenticator, "cusec", cusec);
431 if (res != SHISHI_OK)
432 return res;
434 return SHISHI_OK;
438 shishi_authenticator_cname_get (Shishi * handle,
439 Shishi_asn1 authenticator,
440 char *cname, int *cnamelen)
442 return shishi_principal_name_get (handle, authenticator,
443 "cname", cname, cnamelen);
447 shishi_authenticator_cnamerealm_get (Shishi * handle,
448 Shishi_asn1 authenticator,
449 char *cnamerealm, int *cnamerealmlen)
451 return shishi_principal_name_realm_get (handle, authenticator,
452 "cname",
453 authenticator,
454 "crealm",
455 cnamerealm, cnamerealmlen);
459 shishi_authenticator_remove_cksum (Shishi * handle, Shishi_asn1 authenticator)
461 int res;
463 /* XXX remove this function */
465 res = shishi_asn1_write (handle, authenticator, "cksum", NULL, 0);
466 if (res != SHISHI_OK)
467 return res;
469 return SHISHI_OK;
473 * shishi_authenticator_cksum:
474 * @handle: shishi handle as allocated by shishi_init().
475 * @authenticator: authenticator as allocated by shishi_authenticator().
476 * @cksumtype: output checksum type.
477 * @cksum: output checksum data from authenticator.
478 * @cksumlen: on input, maximum size of output checksum data buffer,
479 * on output, actual size of output checksum data buffer.
481 * Read checksum value from authenticator.
483 * Return value: Returns SHISHI_OK iff successful.
486 shishi_authenticator_cksum (Shishi * handle,
487 Shishi_asn1 authenticator,
488 int32_t * cksumtype,
489 char *cksum, size_t * cksumlen)
491 int res;
493 res = shishi_asn1_read_int32 (handle, authenticator,
494 "cksum.cksumtype", cksumtype);
495 if (res != SHISHI_OK)
496 return res;
498 res = shishi_asn1_read (handle, authenticator, "cksum.checksum",
499 cksum, cksumlen);
500 if (res != SHISHI_OK)
501 return res;
503 return SHISHI_OK;
507 * shishi_authenticator_set_cksum:
508 * @handle: shishi handle as allocated by shishi_init().
509 * @authenticator: authenticator as allocated by shishi_authenticator().
510 * @cksumtype: input checksum type to store in authenticator.
511 * @cksum: input checksum data to store in authenticator.
512 * @cksumlen: size of input checksum data to store in authenticator.
514 * Store checksum value in authenticator. A checksum is usually created
515 * by calling shishi_checksum() on some application specific data using
516 * the key from the ticket that is being used. To save time, you may
517 * want to use shishi_authenticator_add_cksum() instead, which calculates
518 * the checksum and calls this function in one step.
520 * Return value: Returns SHISHI_OK iff successful.
523 shishi_authenticator_set_cksum (Shishi * handle,
524 Shishi_asn1 authenticator,
525 int32_t cksumtype,
526 char *cksum, size_t cksumlen)
528 int res;
530 res = shishi_asn1_write_int32 (handle, authenticator,
531 "cksum.cksumtype", cksumtype);
532 if (res != SHISHI_OK)
533 return res;
535 res = shishi_asn1_write (handle, authenticator, "cksum.checksum",
536 cksum, cksumlen);
537 if (res != SHISHI_OK)
538 return res;
540 return SHISHI_OK;
544 * shishi_authenticator_add_cksum:
545 * @handle: shishi handle as allocated by shishi_init().
546 * @authenticator: authenticator as allocated by shishi_authenticator().
547 * @key: key to to use for encryption.
548 * @keyusage: kerberos key usage value to use in encryption.
549 * @data: input array with data to calculate checksum on.
550 * @datalen: size of input array with data to calculate checksum on.
552 * Calculate checksum for data and store it in the authenticator.
554 * Return value: Returns SHISHI_OK iff successful.
557 shishi_authenticator_add_cksum (Shishi * handle,
558 Shishi_asn1 authenticator,
559 Shishi_key * key,
560 int keyusage, char *data, int datalen)
562 return shishi_authenticator_add_cksum_type (handle, authenticator, key,
563 keyusage,
564 shishi_cipher_defaultcksumtype
565 (shishi_key_type (key)),
566 data, datalen);
570 * shishi_authenticator_add_cksum_type:
571 * @handle: shishi handle as allocated by shishi_init().
572 * @authenticator: authenticator as allocated by shishi_authenticator().
573 * @key: key to to use for encryption.
574 * @keyusage: kerberos key usage value to use in encryption.
575 * @cksumtype: checksum to type to calculate checksum.
576 * @data: input array with data to calculate checksum on.
577 * @datalen: size of input array with data to calculate checksum on.
579 * Calculate checksum for data and store it in the authenticator.
581 * Return value: Returns SHISHI_OK iff successful.
584 shishi_authenticator_add_cksum_type (Shishi * handle,
585 Shishi_asn1 authenticator,
586 Shishi_key * key,
587 int keyusage, int cksumtype,
588 char *data, int datalen)
590 int res;
592 if (data && datalen > 0)
594 char *cksum;
595 int cksumlen;
597 res = shishi_checksum (handle, key, keyusage, cksumtype,
598 data, datalen, &cksum, &cksumlen);
599 if (res != SHISHI_OK)
600 return res;
602 res = shishi_authenticator_set_cksum (handle, authenticator,
603 cksumtype, cksum, cksumlen);
604 free (cksum);
606 else
607 res = shishi_authenticator_remove_cksum (handle, authenticator);
609 return res;
613 * shishi_authenticator_clear_authorizationdata:
614 * @handle: shishi handle as allocated by shishi_init().
615 * @authenticator: Authenticator as allocated by shishi_authenticator().
617 * Remove the authorization-data field from Authenticator.
619 * Return value: Returns SHISHI_OK iff successful.
622 shishi_authenticator_clear_authorizationdata (Shishi * handle,
623 Shishi_asn1 authenticator)
625 int res;
627 res = shishi_asn1_write (handle, authenticator,
628 "authorization-data", NULL, 0);
629 if (res != SHISHI_OK)
630 return SHISHI_ASN1_ERROR;
632 return SHISHI_OK;
636 * shishi_authenticator_add_authorizationdata:
637 * @handle: shishi handle as allocated by shishi_init().
638 * @authenticator: authenticator as allocated by shishi_authenticator().
639 * @adtype: input authorization data type to add.
640 * @addata: input authorization data to add.
641 * @addatalen: size of input authorization data to add.
643 * Add authorization data to authenticator.
645 * Return value: Returns SHISHI_OK iff successful.
648 shishi_authenticator_add_authorizationdata (Shishi * handle,
649 Shishi_asn1 authenticator,
650 int adtype,
651 char *addata, int addatalen)
653 char *format;
654 int res;
655 int i;
657 res = shishi_asn1_write (handle, authenticator,
658 "authorization-data", "NEW", 1);
659 if (res != SHISHI_OK)
660 return res;
662 res = shishi_asn1_number_of_elements (handle, authenticator,
663 "authorization-data", &i);
664 if (res != SHISHI_OK)
665 return res;
667 asprintf (&format, "authorization-data.?%d.ad-type", i);
668 res = shishi_asn1_write_integer (handle, authenticator, format, adtype);
669 if (res != SHISHI_OK)
671 free (format);
672 return res;
675 sprintf (format, "authorization-data.?%d.ad-data", i);
676 res = shishi_asn1_write (handle, authenticator, format, addata, addatalen);
677 free (format);
678 if (res != SHISHI_OK)
679 return res;
681 return SHISHI_OK;
685 * shishi_authenticator_authorizationdata:
686 * @handle: shishi handle as allocated by shishi_init().
687 * @authenticator: authenticator as allocated by shishi_authenticator().
688 * @adtype: output authorization data type.
689 * @addata: output authorization data.
690 * @addatalen: on input, maximum size of output authorization data,
691 * on output, actual size of authorization data.
692 * @nth: element number of authorization-data to extract.
694 * Extract n:th authorization data from authenticator. The first
695 * field is 1.
697 * Return value: Returns SHISHI_OK iff successful.
700 shishi_authenticator_authorizationdata (Shishi * handle,
701 Shishi_asn1 authenticator,
702 int *adtype,
703 char *addata, int *addatalen, int nth)
705 char *format;
706 int res;
707 int i;
709 res = shishi_asn1_number_of_elements (handle, authenticator,
710 "authorization-data", &i);
711 if (res != SHISHI_OK)
712 return SHISHI_ASN1_ERROR;
714 if (nth > i)
715 return SHISHI_OUT_OF_RANGE;
717 asprintf (&format, "authorization-data.?%d.ad-type", nth);
718 res = shishi_asn1_read_int32 (handle, authenticator, format, adtype);
719 free (format);
720 if (res != SHISHI_OK)
721 return res;
723 asprintf (&format, "authorization-data.?%d.ad-data", i);
724 res = shishi_asn1_read (handle, authenticator, format, addata, addatalen);
725 free (format);
726 if (res != SHISHI_OK)
727 return res;
729 return SHISHI_OK;
733 * shishi_authenticator_remove_subkey:
734 * @handle: shishi handle as allocated by shishi_init().
735 * @authenticator: authenticator as allocated by shishi_authenticator().
737 * Remove subkey from the authenticator.
739 * Return value: Returns SHISHI_OK iff successful.
742 shishi_authenticator_remove_subkey (Shishi * handle, Shishi_asn1 authenticator)
744 int res;
746 res = shishi_asn1_write (handle, authenticator, "subkey", NULL, 0);
747 if (res != SHISHI_OK)
748 return res;
750 return SHISHI_OK;
754 * shishi_authenticator_get_subkey:
755 * @handle: shishi handle as allocated by shishi_init().
756 * @authenticator: authenticator as allocated by shishi_authenticator().
757 * @subkey: output newly allocated subkey from authenticator.
759 * Read subkey value from authenticator.
761 * Return value: Returns SHISHI_OK if successful or SHISHI_ASN1_NO_ELEMENT
762 * if subkey is not present.
765 shishi_authenticator_get_subkey (Shishi * handle,
766 Shishi_asn1 authenticator,
767 Shishi_key ** subkey)
769 int res;
770 int subkeytype;
771 char * subkeyvalue;
772 size_t subkeylen;
773 int n;
775 res = shishi_asn1_number_of_elements (handle, authenticator,
776 "subkey", &n);
777 if (res != SHISHI_OK)
778 return res;
780 res = shishi_asn1_read_int32 (handle, authenticator,
781 "subkey.keytype", &subkeytype);
782 if (res != SHISHI_OK)
783 return res;
785 res = shishi_asn1_read2 (handle, authenticator, "subkey.keyvalue",
786 &subkeyvalue, &subkeylen);
787 if (res != SHISHI_OK)
788 return res;
790 res = shishi_key (handle, subkey);
791 if (res != SHISHI_OK)
792 return res;
794 shishi_key_type_set (*subkey, subkeytype);
795 shishi_key_value_set (*subkey, subkeyvalue);
797 return SHISHI_OK;
801 * shishi_authenticator_set_subkey:
802 * @handle: shishi handle as allocated by shishi_init().
803 * @authenticator: authenticator as allocated by shishi_authenticator().
804 * @subkeytype: input subkey type to store in authenticator.
805 * @subkey: input subkey data to store in authenticator.
806 * @subkeylen: size of input subkey data to store in authenticator.
808 * Store subkey value in authenticator. A subkey is usually created
809 * by calling shishi_key_random() using the default encryption type of
810 * the key from the ticket that is being used. To save time, you may
811 * want to use shishi_authenticator_add_subkey() instead, which calculates
812 * the subkey and calls this function in one step.
814 * Return value: Returns SHISHI_OK iff successful.
817 shishi_authenticator_set_subkey (Shishi * handle,
818 Shishi_asn1 authenticator,
819 int32_t subkeytype,
820 char *subkey, size_t subkeylen)
822 int res;
824 res = shishi_asn1_write_int32 (handle, authenticator,
825 "subkey.keytype", subkeytype);
826 if (res != SHISHI_OK)
827 return res;
829 res = shishi_asn1_write (handle, authenticator, "subkey.keyvalue",
830 subkey, subkeylen);
831 if (res != SHISHI_OK)
832 return res;
834 return SHISHI_OK;
838 * shishi_authenticator_add_random_subkey:
839 * @handle: shishi handle as allocated by shishi_init().
840 * @authenticator: authenticator as allocated by shishi_authenticator().
842 * Generate random subkey and store it in the authenticator.
844 * Return value: Returns SHISHI_OK iff successful.
847 shishi_authenticator_add_random_subkey (Shishi * handle,
848 Shishi_asn1 authenticator)
850 int res;
851 int * etypes;
852 Shishi_key * subkey;
854 res = shishi_cfg_clientkdcetype (handle, &etypes);
855 if (!res)
856 return res;
858 res = shishi_key_random (handle, etypes[0], &subkey);
859 if (res != SHISHI_OK)
860 return res;
862 res = shishi_authenticator_set_subkey (handle, authenticator,
863 shishi_key_type (subkey),
864 shishi_key_value (subkey),
865 shishi_key_length (subkey));
867 shishi_key_done (subkey);
869 return res;
873 * shishi_authenticator_add_subkey:
874 * @handle: shishi handle as allocated by shishi_init().
875 * @authenticator: authenticator as allocated by shishi_authenticator().
876 * @subkey: subkey to add to authenticator.
878 * Store subkey in the authenticator.
880 * Return value: Returns SHISHI_OK iff successful.
883 shishi_authenticator_add_subkey (Shishi * handle,
884 Shishi_asn1 authenticator,
885 Shishi_key * subkey)
887 int res;
888 int * etypes;
890 res = shishi_cfg_clientkdcetype (handle, &etypes);
891 if (res != SHISHI_OK)
892 return res;
894 res = shishi_authenticator_set_subkey (handle, authenticator,
895 shishi_key_type (subkey),
896 shishi_key_value (subkey),
897 shishi_key_length (subkey));
899 return res;