1 /* seskey.c - Session key routines
2 * Copyright (C) 1998-2012 Free Software Foundation, Inc.
6 * This file is part of OpenCDK.
8 * The OpenCDK library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
34 * @ret_s2k: output for the new S2K object
35 * @mode: the S2K mode (simple, salted, iter+salted)
36 * @digest_algo: the hash algorithm
39 * Create a new S2K object with the given parameter.
40 * The @salt parameter must be always 8 octets.
43 cdk_s2k_new (cdk_s2k_t
* ret_s2k
, int mode
, int digest_algo
,
51 if (mode
!= 0x00 && mode
!= 0x01 && mode
!= 0x03)
54 if (_gnutls_hash_get_algo_len (digest_algo
) <= 0)
57 s2k
= cdk_calloc (1, sizeof *s2k
);
59 return CDK_Out_Of_Core
;
61 s2k
->hash_algo
= digest_algo
;
63 memcpy (s2k
->salt
, salt
, 8);
71 * @s2k: the S2K object
73 * Release the given S2K object.
76 cdk_s2k_free (cdk_s2k_t s2k
)
82 /* Make a copy of the source s2k into R_DST. */
84 _cdk_s2k_copy (cdk_s2k_t
* r_dst
, cdk_s2k_t src
)
89 err
= cdk_s2k_new (&dst
, src
->mode
, src
->hash_algo
, src
->salt
);
92 dst
->count
= src
->count
;