2 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
3 * Software Foundation, Inc.
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GNUTLS.
9 * The GNUTLS library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 /* Functions on OpenPGP privkey parsing
29 #include <gnutls_int.h>
30 #include <gnutls_datum.h>
31 #include <gnutls_global.h>
32 #include <gnutls_errors.h>
33 #include <gnutls_num.h>
34 #include <openpgp_int.h>
35 #include <gnutls_openpgp.h>
36 #include <gnutls_cert.h>
39 * gnutls_openpgp_privkey_init - initializes a #gnutls_openpgp_privkey_t structure
40 * @key: The structure to be initialized
42 * This function will initialize an OpenPGP key structure.
44 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
47 gnutls_openpgp_privkey_init (gnutls_openpgp_privkey_t
* key
)
49 *key
= gnutls_calloc (1, sizeof (gnutls_openpgp_privkey_int
));
52 return 0; /* success */
53 return GNUTLS_E_MEMORY_ERROR
;
57 * gnutls_openpgp_privkey_deinit - deinitializes memory used by a #gnutls_openpgp_privkey_t structure
58 * @key: The structure to be initialized
60 * This function will deinitialize a key structure.
63 gnutls_openpgp_privkey_deinit (gnutls_openpgp_privkey_t key
)
70 cdk_kbnode_release (key
->knode
);
78 * gnutls_openpgp_privkey_import - import a RAW or BASE64 encoded key
79 * @key: The structure to store the parsed key.
80 * @data: The RAW or BASE64 encoded key.
81 * @format: One of #gnutls_openpgp_crt_fmt_t elements.
82 * @password: not used for now
83 * @flags: should be zero
85 * This function will convert the given RAW or Base64 encoded key to
86 * the native gnutls_openpgp_privkey_t format. The output will be
89 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
92 gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key
,
93 const gnutls_datum_t
* data
,
94 gnutls_openpgp_crt_fmt_t format
,
95 const char *password
, unsigned int flags
)
101 if (data
->data
== NULL
|| data
->size
== 0)
104 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
107 if (format
== GNUTLS_OPENPGP_FMT_RAW
)
109 rc
= cdk_kbnode_read_from_mem (&key
->knode
, data
->data
, data
->size
);
112 rc
= _gnutls_map_cdk_rc (rc
);
119 rc
= cdk_stream_tmp_from_mem (data
->data
, data
->size
, &inp
);
122 rc
= _gnutls_map_cdk_rc (rc
);
127 if (cdk_armor_filter_use (inp
))
129 rc
= cdk_stream_set_armor_flag (inp
, 0);
132 rc
= _gnutls_map_cdk_rc (rc
);
133 cdk_stream_close (inp
);
139 rc
= cdk_keydb_get_keyblock (inp
, &key
->knode
);
140 cdk_stream_close (inp
);
144 rc
= _gnutls_map_cdk_rc (rc
);
150 /* Test if the import was successful. */
151 pkt
= cdk_kbnode_find_packet (key
->knode
, CDK_PKT_SECRET_KEY
);
155 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
162 * gnutls_openpgp_privkey_export - export a RAW or BASE64 encoded key
163 * @key: Holds the key.
164 * @format: One of gnutls_openpgp_crt_fmt_t elements.
165 * @password: the password that will be used to encrypt the key. (unused for now)
166 * @flags: zero for future compatibility
167 * @output_data: will contain the key base64 encoded or raw
168 * @output_data_size: holds the size of output_data (and will be
169 * replaced by the actual size of parameters)
171 * This function will convert the given key to RAW or Base64 format.
172 * If the buffer provided is not long enough to hold the output, then
173 * GNUTLS_E_SHORT_MEMORY_BUFFER will be returned.
175 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
180 gnutls_openpgp_privkey_export (gnutls_openpgp_privkey_t key
,
181 gnutls_openpgp_crt_fmt_t format
,
182 const char *password
, unsigned int flags
,
183 void *output_data
, size_t * output_data_size
)
185 /* FIXME for now we do not export encrypted keys */
186 return _gnutls_openpgp_export (key
->knode
, format
, output_data
,
187 output_data_size
, 1);
192 * gnutls_openpgp_privkey_get_pk_algorithm - return the key's PublicKey algorithm
193 * @key: is an OpenPGP key
194 * @bits: if bits is non null it will hold the size of the parameters' in bits
196 * This function will return the public key algorithm of an OpenPGP
199 * If bits is non null, it should have enough size to hold the parameters
200 * size in bits. For RSA the bits returned is the modulus.
201 * For DSA the bits returned are of the public exponent.
203 * Returns: a member of the #gnutls_pk_algorithm_t enumeration on
204 * success, or a negative value on error.
208 gnutls_pk_algorithm_t
209 gnutls_openpgp_privkey_get_pk_algorithm (gnutls_openpgp_privkey_t key
,
218 return GNUTLS_PK_UNKNOWN
;
222 pkt
= cdk_kbnode_find_packet (key
->knode
, CDK_PKT_SECRET_KEY
);
226 *bits
= cdk_pk_get_nbits (pkt
->pkt
.secret_key
->pk
);
227 algo
= _gnutls_openpgp_get_algo (pkt
->pkt
.secret_key
->pk
->pubkey_algo
);
234 _gnutls_openpgp_get_algo (int cdk_algo
)
238 if (is_RSA (cdk_algo
))
239 algo
= GNUTLS_PK_RSA
;
240 else if (is_DSA (cdk_algo
))
241 algo
= GNUTLS_PK_DSA
;
244 _gnutls_x509_log ("Unknown OpenPGP algorithm %d\n", cdk_algo
);
245 algo
= GNUTLS_PK_UNKNOWN
;
252 * gnutls_openpgp_privkey_get_revoked_ status - Get the revoked status of the key
253 * @key: the structure that contains the OpenPGP private key.
255 * Get revocation status of key.
257 * Returns: true (1) if the key has been revoked, or false (0) if it
258 * has not, or a negative value indicates an error.
263 gnutls_openpgp_privkey_get_revoked_status (gnutls_openpgp_privkey_t key
)
270 return GNUTLS_E_INVALID_REQUEST
;
273 pkt
= cdk_kbnode_find_packet (key
->knode
, CDK_PKT_SECRET_KEY
);
275 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
277 if (pkt
->pkt
.secret_key
->is_revoked
!= 0)
283 * gnutls_openpgp_privkey_get_fingerprint - Gets the fingerprint
284 * @key: the raw data that contains the OpenPGP secret key.
285 * @fpr: the buffer to save the fingerprint, must hold at least 20 bytes.
286 * @fprlen: the integer to save the length of the fingerprint.
288 * Get the fingerprint of the OpenPGP key. Depends on the
289 * algorithm, the fingerprint can be 16 or 20 bytes.
291 * Returns: On success, 0 is returned, or an error code.
296 gnutls_openpgp_privkey_get_fingerprint (gnutls_openpgp_privkey_t key
,
297 void *fpr
, size_t * fprlen
)
300 cdk_pkt_pubkey_t pk
= NULL
;
305 return GNUTLS_E_INVALID_REQUEST
;
310 pkt
= cdk_kbnode_find_packet (key
->knode
, CDK_PKT_SECRET_KEY
);
314 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
317 pk
= pkt
->pkt
.secret_key
->pk
;
320 if (is_RSA (pk
->pubkey_algo
) && pk
->version
< 4)
323 cdk_pk_get_fingerprint (pk
, fpr
);
329 * gnutls_openpgp_privkey_get_key_id - Gets the keyID
330 * @key: the structure that contains the OpenPGP secret key.
331 * @keyid: the buffer to save the keyid.
335 * Returns: the 64-bit keyID of the OpenPGP key.
340 gnutls_openpgp_privkey_get_key_id (gnutls_openpgp_privkey_t key
,
341 gnutls_openpgp_keyid_t keyid
)
349 return GNUTLS_E_INVALID_REQUEST
;
352 pkt
= cdk_kbnode_find_packet (key
->knode
, CDK_PKT_SECRET_KEY
);
354 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
356 cdk_sk_get_keyid (pkt
->pkt
.secret_key
, kid
);
357 _gnutls_write_uint32 (kid
[0], keyid
);
358 _gnutls_write_uint32 (kid
[1], keyid
+ 4);
365 * gnutls_openpgp_privkey_get_subkey_count - return the number of subkeys
366 * @key: is an OpenPGP key
368 * This function will return the number of subkeys present in the
369 * given OpenPGP certificate.
371 * Returns: the number of subkeys, or a negative value on error.
376 gnutls_openpgp_privkey_get_subkey_count (gnutls_openpgp_privkey_t key
)
390 while ((p
= cdk_kbnode_walk (key
->knode
, &ctx
, 0)))
392 pkt
= cdk_kbnode_get_packet (p
);
393 if (pkt
->pkttype
== CDK_PKT_SECRET_SUBKEY
)
400 /* returns the subkey with the given index */
402 _get_secret_subkey (gnutls_openpgp_privkey_t key
, unsigned int indx
)
406 unsigned int subkeys
;
410 while ((p
= cdk_kbnode_walk (key
->knode
, &ctx
, 0)))
412 pkt
= cdk_kbnode_get_packet (p
);
413 if (pkt
->pkttype
== CDK_PKT_SECRET_SUBKEY
&& indx
== subkeys
++)
421 * gnutls_openpgp_privkey_get_subkey_revoked_ status - Get the revoked status of the key
422 * @key: the structure that contains the OpenPGP private key.
423 * @idx: is the subkey index
425 * Get revocation status of key.
427 * Returns: true (1) if the key has been revoked, or false (0) if it
428 * has not, or a negative value indicates an error.
433 gnutls_openpgp_privkey_get_subkey_revoked_status (gnutls_openpgp_privkey_t
434 key
, unsigned int idx
)
441 return GNUTLS_E_INVALID_REQUEST
;
444 pkt
= _get_secret_subkey (key
, idx
);
446 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
448 if (pkt
->pkt
.secret_key
->is_revoked
!= 0)
454 * gnutls_openpgp_privkey_get_subkey_pk_algorithm - return the subkey's PublicKey algorithm
455 * @key: is an OpenPGP key
456 * @idx: is the subkey index
457 * @bits: if bits is non null it will hold the size of the parameters' in bits
459 * This function will return the public key algorithm of a subkey of an OpenPGP
462 * If bits is non null, it should have enough size to hold the parameters
463 * size in bits. For RSA the bits returned is the modulus.
464 * For DSA the bits returned are of the public exponent.
466 * Returns: a member of the #gnutls_pk_algorithm_t enumeration on
467 * success, or a negative value on error.
471 gnutls_pk_algorithm_t
472 gnutls_openpgp_privkey_get_subkey_pk_algorithm (gnutls_openpgp_privkey_t key
,
482 return GNUTLS_PK_UNKNOWN
;
485 pkt
= _get_secret_subkey (key
, idx
);
491 *bits
= cdk_pk_get_nbits (pkt
->pkt
.secret_key
->pk
);
492 algo
= pkt
->pkt
.secret_key
->pubkey_algo
;
494 algo
= GNUTLS_PK_RSA
;
495 else if (is_DSA (algo
))
496 algo
= GNUTLS_PK_DSA
;
498 algo
= GNUTLS_E_UNKNOWN_PK_ALGORITHM
;
505 * gnutls_openpgp_privkey_get_subkey_idx - Returns the subkey's index
506 * @key: the structure that contains the OpenPGP private key.
509 * Get index of subkey.
511 * Returns: the index of the subkey or a negative error value.
516 gnutls_openpgp_privkey_get_subkey_idx (gnutls_openpgp_privkey_t key
,
517 const gnutls_openpgp_keyid_t keyid
)
525 return GNUTLS_E_INVALID_REQUEST
;
528 KEYID_IMPORT (kid
, keyid
);
529 ret
= _gnutls_openpgp_find_subkey_idx (key
->knode
, kid
, 1);
540 * gnutls_openpgp_privkey_get_subkey_creation_time - Extract the timestamp
541 * @key: the structure that contains the OpenPGP private key.
542 * @idx: the subkey index
544 * Get subkey creation time.
546 * Returns: the timestamp when the OpenPGP key was created.
551 gnutls_openpgp_privkey_get_subkey_creation_time (gnutls_openpgp_privkey_t key
,
560 pkt
= _get_secret_subkey (key
, idx
);
562 timestamp
= pkt
->pkt
.secret_key
->pk
->timestamp
;
570 * gnutls_openpgp_privkey_get_subkey_expiration_time - Extract the expire date
571 * @key: the structure that contains the OpenPGP private key.
572 * @idx: the subkey index
574 * Get subkey expiration time. A value of '0' means that the key
575 * doesn't expire at all.
577 * Returns: the time when the OpenPGP key expires.
582 gnutls_openpgp_privkey_get_subkey_expiration_time (gnutls_openpgp_privkey_t
583 key
, unsigned int idx
)
591 pkt
= _get_secret_subkey (key
, idx
);
593 expiredate
= pkt
->pkt
.secret_key
->expiredate
;
601 * gnutls_openpgp_privkey_get_subkey_id - Gets the keyID
602 * @key: the structure that contains the OpenPGP secret key.
603 * @idx: the subkey index
604 * @keyid: the buffer to save the keyid.
606 * Get the key-id for the subkey.
608 * Returns: the 64-bit keyID of the OpenPGP key.
613 gnutls_openpgp_privkey_get_subkey_id (gnutls_openpgp_privkey_t key
,
615 gnutls_openpgp_keyid_t keyid
)
623 return GNUTLS_E_INVALID_REQUEST
;
626 pkt
= _get_secret_subkey (key
, idx
);
628 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
630 cdk_sk_get_keyid (pkt
->pkt
.secret_key
, kid
);
631 _gnutls_write_uint32 (kid
[0], keyid
);
632 _gnutls_write_uint32 (kid
[1], keyid
+ 4);
638 * gnutls_openpgp_privkey_get_subkey_fingerprint - Gets the fingerprint of a subkey
639 * @key: the raw data that contains the OpenPGP secret key.
640 * @idx: the subkey index
641 * @fpr: the buffer to save the fingerprint, must hold at least 20 bytes.
642 * @fprlen: the integer to save the length of the fingerprint.
644 * Get the fingerprint of an OpenPGP subkey. Depends on the
645 * algorithm, the fingerprint can be 16 or 20 bytes.
647 * Returns: On success, 0 is returned, or an error code.
652 gnutls_openpgp_privkey_get_subkey_fingerprint (gnutls_openpgp_privkey_t key
,
654 void *fpr
, size_t * fprlen
)
657 cdk_pkt_pubkey_t pk
= NULL
;
662 return GNUTLS_E_INVALID_REQUEST
;
667 pkt
= _get_secret_subkey (key
, idx
);
669 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
672 pk
= pkt
->pkt
.secret_key
->pk
;
675 if (is_RSA (pk
->pubkey_algo
) && pk
->version
< 4)
678 cdk_pk_get_fingerprint (pk
, fpr
);
683 /* Extracts DSA and RSA parameters from a certificate.
686 _gnutls_openpgp_privkey_get_mpis (gnutls_openpgp_privkey_t pkey
,
687 uint32_t * keyid
/*[2] */ ,
688 bigint_t
* params
, int *params_size
)
691 int pk_algorithm
, local_params
;
695 pkt
= cdk_kbnode_find_packet (pkey
->knode
, CDK_PKT_SECRET_KEY
);
697 pkt
= _gnutls_openpgp_find_key (pkey
->knode
, keyid
, 1);
702 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
706 _gnutls_openpgp_get_algo (pkt
->pkt
.secret_key
->pk
->pubkey_algo
);
708 switch (pk_algorithm
)
711 local_params
= RSA_PRIVATE_PARAMS
;
714 local_params
= DSA_PRIVATE_PARAMS
;
718 return GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE
;
721 if (*params_size
< local_params
)
724 return GNUTLS_E_INTERNAL_ERROR
;
727 *params_size
= local_params
;
730 for (i
= 0; i
< local_params
; i
++)
732 result
= _gnutls_read_pgp_mpi (pkt
, 1, i
, ¶ms
[i
]);
745 for (j
= 0; j
< i
; j
++)
746 _gnutls_mpi_release (¶ms
[j
]);
752 /* The internal version of export
755 _get_sk_rsa_raw (gnutls_openpgp_privkey_t pkey
, gnutls_openpgp_keyid_t keyid
,
756 gnutls_datum_t
* m
, gnutls_datum_t
* e
,
757 gnutls_datum_t
* d
, gnutls_datum_t
* p
,
758 gnutls_datum_t
* q
, gnutls_datum_t
* u
)
760 int pk_algorithm
, ret
, i
;
763 bigint_t params
[MAX_PRIV_PARAMS_SIZE
];
764 int params_size
= MAX_PRIV_PARAMS_SIZE
;
769 return GNUTLS_E_INVALID_REQUEST
;
772 KEYID_IMPORT (kid32
, keyid
);
774 pkt
= _gnutls_openpgp_find_key (pkey
->knode
, kid32
, 1);
778 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
782 _gnutls_openpgp_get_algo (pkt
->pkt
.secret_key
->pk
->pubkey_algo
);
784 if (pk_algorithm
!= GNUTLS_PK_RSA
)
787 return GNUTLS_E_INVALID_REQUEST
;
790 ret
= _gnutls_openpgp_privkey_get_mpis (pkey
, kid32
, params
, ¶ms_size
);
797 ret
= _gnutls_mpi_dprint (params
[0], m
);
804 ret
= _gnutls_mpi_dprint (params
[1], e
);
808 _gnutls_free_datum (m
);
812 ret
= _gnutls_mpi_dprint (params
[2], d
);
816 _gnutls_free_datum (m
);
817 _gnutls_free_datum (e
);
821 ret
= _gnutls_mpi_dprint (params
[3], p
);
825 _gnutls_free_datum (m
);
826 _gnutls_free_datum (e
);
827 _gnutls_free_datum (d
);
831 ret
= _gnutls_mpi_dprint (params
[4], q
);
835 _gnutls_free_datum (m
);
836 _gnutls_free_datum (e
);
837 _gnutls_free_datum (d
);
838 _gnutls_free_datum (p
);
842 ret
= _gnutls_mpi_dprint (params
[5], u
);
846 _gnutls_free_datum (q
);
847 _gnutls_free_datum (m
);
848 _gnutls_free_datum (e
);
849 _gnutls_free_datum (d
);
850 _gnutls_free_datum (p
);
857 for (i
= 0; i
< params_size
; i
++)
859 _gnutls_mpi_release (¶ms
[i
]);
865 _get_sk_dsa_raw (gnutls_openpgp_privkey_t pkey
, gnutls_openpgp_keyid_t keyid
,
866 gnutls_datum_t
* p
, gnutls_datum_t
* q
,
867 gnutls_datum_t
* g
, gnutls_datum_t
* y
, gnutls_datum_t
* x
)
869 int pk_algorithm
, ret
, i
;
872 bigint_t params
[MAX_PRIV_PARAMS_SIZE
];
873 int params_size
= MAX_PRIV_PARAMS_SIZE
;
878 return GNUTLS_E_INVALID_REQUEST
;
881 KEYID_IMPORT (kid32
, keyid
);
883 pkt
= _gnutls_openpgp_find_key (pkey
->knode
, kid32
, 1);
887 return GNUTLS_E_OPENPGP_GETKEY_FAILED
;
891 _gnutls_openpgp_get_algo (pkt
->pkt
.secret_key
->pk
->pubkey_algo
);
893 if (pk_algorithm
!= GNUTLS_PK_DSA
)
896 return GNUTLS_E_INVALID_REQUEST
;
899 ret
= _gnutls_openpgp_privkey_get_mpis (pkey
, kid32
, params
, ¶ms_size
);
907 ret
= _gnutls_mpi_dprint (params
[0], p
);
915 ret
= _gnutls_mpi_dprint (params
[1], q
);
919 _gnutls_free_datum (p
);
925 ret
= _gnutls_mpi_dprint (params
[2], g
);
929 _gnutls_free_datum (p
);
930 _gnutls_free_datum (q
);
936 ret
= _gnutls_mpi_dprint (params
[3], y
);
940 _gnutls_free_datum (p
);
941 _gnutls_free_datum (g
);
942 _gnutls_free_datum (q
);
946 ret
= _gnutls_mpi_dprint (params
[4], x
);
950 _gnutls_free_datum (y
);
951 _gnutls_free_datum (p
);
952 _gnutls_free_datum (g
);
953 _gnutls_free_datum (q
);
960 for (i
= 0; i
< params_size
; i
++)
962 _gnutls_mpi_release (¶ms
[i
]);
969 * gnutls_openpgp_privkey_export_rsa_raw - This function will export the RSA private key
970 * @pkey: Holds the certificate
971 * @m: will hold the modulus
972 * @e: will hold the public exponent
973 * @d: will hold the private exponent
974 * @p: will hold the first prime (p)
975 * @q: will hold the second prime (q)
976 * @u: will hold the coefficient
978 * This function will export the RSA private key's parameters found in
979 * the given structure. The new parameters will be allocated using
980 * gnutls_malloc() and will be stored in the appropriate datum.
982 * Returns: %GNUTLS_E_SUCCESS on success, otherwise an error.
987 gnutls_openpgp_privkey_export_rsa_raw (gnutls_openpgp_privkey_t pkey
,
988 gnutls_datum_t
* m
, gnutls_datum_t
* e
,
989 gnutls_datum_t
* d
, gnutls_datum_t
* p
,
990 gnutls_datum_t
* q
, gnutls_datum_t
* u
)
992 gnutls_openpgp_keyid_t keyid
;
995 ret
= gnutls_openpgp_privkey_get_key_id (pkey
, keyid
);
1002 return _get_sk_rsa_raw (pkey
, keyid
, m
, e
, d
, p
, q
, u
);
1006 * gnutls_openpgp_privkey_export_dsa_raw - This function will export the DSA private key
1007 * @pkey: Holds the certificate
1008 * @p: will hold the p
1009 * @q: will hold the q
1010 * @g: will hold the g
1011 * @y: will hold the y
1012 * @x: will hold the x
1014 * This function will export the DSA private key's parameters found in
1015 * the given certificate. The new parameters will be allocated using
1016 * gnutls_malloc() and will be stored in the appropriate datum.
1018 * Returns: %GNUTLS_E_SUCCESS on success, otherwise an error.
1023 gnutls_openpgp_privkey_export_dsa_raw (gnutls_openpgp_privkey_t pkey
,
1024 gnutls_datum_t
* p
, gnutls_datum_t
* q
,
1025 gnutls_datum_t
* g
, gnutls_datum_t
* y
,
1028 gnutls_openpgp_keyid_t keyid
;
1031 ret
= gnutls_openpgp_privkey_get_key_id (pkey
, keyid
);
1038 return _get_sk_dsa_raw (pkey
, keyid
, p
, q
, g
, y
, x
);
1042 * gnutls_openpgp_privkey_export_subkey_rsa_raw - export the RSA private key
1043 * @pkey: Holds the certificate
1044 * @idx: Is the subkey index
1045 * @m: will hold the modulus
1046 * @e: will hold the public exponent
1047 * @d: will hold the private exponent
1048 * @p: will hold the first prime (p)
1049 * @q: will hold the second prime (q)
1050 * @u: will hold the coefficient
1052 * This function will export the RSA private key's parameters found in
1053 * the given structure. The new parameters will be allocated using
1054 * gnutls_malloc() and will be stored in the appropriate datum.
1056 * Returns: %GNUTLS_E_SUCCESS on success, otherwise an error.
1061 gnutls_openpgp_privkey_export_subkey_rsa_raw (gnutls_openpgp_privkey_t pkey
,
1070 gnutls_openpgp_keyid_t keyid
;
1073 ret
= gnutls_openpgp_privkey_get_subkey_id (pkey
, idx
, keyid
);
1080 return _get_sk_rsa_raw (pkey
, keyid
, m
, e
, d
, p
, q
, u
);
1084 * gnutls_openpgp_privkey_export_subkey_dsa_raw - export the DSA private key
1085 * @pkey: Holds the certificate
1086 * @idx: Is the subkey index
1087 * @p: will hold the p
1088 * @q: will hold the q
1089 * @g: will hold the g
1090 * @y: will hold the y
1091 * @x: will hold the x
1093 * This function will export the DSA private key's parameters found
1094 * in the given certificate. The new parameters will be allocated
1095 * using gnutls_malloc() and will be stored in the appropriate datum.
1097 * Returns: %GNUTLS_E_SUCCESS on success, otherwise an error.
1102 gnutls_openpgp_privkey_export_subkey_dsa_raw (gnutls_openpgp_privkey_t pkey
,
1110 gnutls_openpgp_keyid_t keyid
;
1113 ret
= gnutls_openpgp_privkey_get_subkey_id (pkey
, idx
, keyid
);
1120 return _get_sk_dsa_raw (pkey
, keyid
, p
, q
, g
, y
, x
);
1124 * gnutls_openpgp_privkey_get_preferred_key_id - Gets the preferred keyID
1125 * @key: the structure that contains the OpenPGP public key.
1126 * @keyid: the struct to save the keyid.
1128 * Get the preferred key-id for the key.
1130 * Returns: the 64-bit preferred keyID of the OpenPGP key, or if it
1131 * hasn't been set it returns %GNUTLS_E_INVALID_REQUEST.
1134 gnutls_openpgp_privkey_get_preferred_key_id (gnutls_openpgp_privkey_t key
,
1135 gnutls_openpgp_keyid_t keyid
)
1137 if (!key
|| !keyid
|| !key
->preferred_set
)
1140 return GNUTLS_E_INVALID_REQUEST
;
1143 memcpy (keyid
, key
->preferred_keyid
, sizeof (gnutls_openpgp_keyid_t
));
1149 * gnutls_openpgp_privkey_set_preferred_key_id - Set the preferred keyID
1150 * @key: the structure that contains the OpenPGP public key.
1151 * @keyid: the selected keyid
1153 * This allows setting a preferred key id for the given certificate.
1154 * This key will be used by functions that involve key handling.
1156 * Returns: On success, 0 is returned, or an error code.
1159 gnutls_openpgp_privkey_set_preferred_key_id (gnutls_openpgp_privkey_t key
,
1160 const gnutls_openpgp_keyid_t
1168 return GNUTLS_E_INVALID_REQUEST
;
1171 /* check if the id is valid */
1172 ret
= gnutls_openpgp_privkey_get_subkey_idx (key
, keyid
);
1175 _gnutls_x509_log ("the requested subkey does not exist\n");
1180 key
->preferred_set
= 1;
1181 memcpy (key
->preferred_keyid
, keyid
, sizeof (gnutls_openpgp_keyid_t
));