dst_parse.h revision aaaf8d4f4873d21e55c3ffb4f656203d08339865
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews/*
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * Portions Copyright (C) 2004-2010 Internet Systems Consortium, Inc. ("ISC")
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * Portions Copyright (C) 2000-2002 Internet Software Consortium.
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews *
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * purpose with or without fee is hereby granted, provided that the above
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * copyright notice and this permission notice appear in all copies.
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews *
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews *
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * Portions Copyright (C) 1995-2000 by Network Associates, Inc.
a8f061d5c61bbdbe922cbb0adb70ae81770b52cbMark Andrews *
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * purpose with or without fee is hereby granted, provided that the above
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * copyright notice and this permission notice appear in all copies.
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews *
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC AND NETWORK ASSOCIATES DISCLAIMS
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews */
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews/* $Id: dst_parse.h,v 1.17 2010/12/23 23:47:08 tbox Exp $ */
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews/*! \file */
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#ifndef DST_DST_PARSE_H
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define DST_DST_PARSE_H 1
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#include <isc/lang.h>
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#include <dst/dst.h>
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define MAXFIELDSIZE 512
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews/*
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * Maximum number of fields in a private file is 18 (12 algorithm-
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews * specific fields for RSA, plus 6 generic fields).
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews */
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define MAXFIELDS 12+6
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_SHIFT 4
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_ALG(tag) ((unsigned int)(tag) >> TAG_SHIFT)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG(alg, off) (((alg) << TAG_SHIFT) + (off))
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews/* These are used by both RSA-MD5 and RSA-SHA1 */
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define RSA_NTAGS 11
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_RSA_MODULUS ((DST_ALG_RSAMD5 << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_RSA_PUBLICEXPONENT ((DST_ALG_RSAMD5 << TAG_SHIFT) + 1)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_RSA_PRIVATEEXPONENT ((DST_ALG_RSAMD5 << TAG_SHIFT) + 2)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_RSA_PRIME1 ((DST_ALG_RSAMD5 << TAG_SHIFT) + 3)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_RSA_PRIME2 ((DST_ALG_RSAMD5 << TAG_SHIFT) + 4)
a8f061d5c61bbdbe922cbb0adb70ae81770b52cbMark Andrews#define TAG_RSA_EXPONENT1 ((DST_ALG_RSAMD5 << TAG_SHIFT) + 5)
a8f061d5c61bbdbe922cbb0adb70ae81770b52cbMark Andrews#define TAG_RSA_EXPONENT2 ((DST_ALG_RSAMD5 << TAG_SHIFT) + 6)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_RSA_COEFFICIENT ((DST_ALG_RSAMD5 << TAG_SHIFT) + 7)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_RSA_ENGINE ((DST_ALG_RSAMD5 << TAG_SHIFT) + 8)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_RSA_LABEL ((DST_ALG_RSAMD5 << TAG_SHIFT) + 9)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_RSA_PIN ((DST_ALG_RSAMD5 << TAG_SHIFT) + 10)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define DH_NTAGS 4
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_DH_PRIME ((DST_ALG_DH << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_DH_GENERATOR ((DST_ALG_DH << TAG_SHIFT) + 1)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_DH_PRIVATE ((DST_ALG_DH << TAG_SHIFT) + 2)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_DH_PUBLIC ((DST_ALG_DH << TAG_SHIFT) + 3)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define DSA_NTAGS 5
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_DSA_PRIME ((DST_ALG_DSA << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_DSA_SUBPRIME ((DST_ALG_DSA << TAG_SHIFT) + 1)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_DSA_BASE ((DST_ALG_DSA << TAG_SHIFT) + 2)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_DSA_PRIVATE ((DST_ALG_DSA << TAG_SHIFT) + 3)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_DSA_PUBLIC ((DST_ALG_DSA << TAG_SHIFT) + 4)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define GOST_NTAGS 1
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_GOST_PRIVASN1 ((DST_ALG_ECCGOST << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define ECDSA_NTAGS 1
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_ECDSA_PRIVATEKEY ((DST_ALG_ECDSA256 << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define OLD_HMACMD5_NTAGS 1
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define HMACMD5_NTAGS 2
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACMD5_KEY ((DST_ALG_HMACMD5 << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACMD5_BITS ((DST_ALG_HMACMD5 << TAG_SHIFT) + 1)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define HMACSHA1_NTAGS 2
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA1_KEY ((DST_ALG_HMACSHA1 << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA1_BITS ((DST_ALG_HMACSHA1 << TAG_SHIFT) + 1)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define HMACSHA224_NTAGS 2
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA224_KEY ((DST_ALG_HMACSHA224 << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA224_BITS ((DST_ALG_HMACSHA224 << TAG_SHIFT) + 1)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define HMACSHA256_NTAGS 2
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA256_KEY ((DST_ALG_HMACSHA256 << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA256_BITS ((DST_ALG_HMACSHA256 << TAG_SHIFT) + 1)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define HMACSHA384_NTAGS 2
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA384_KEY ((DST_ALG_HMACSHA384 << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA384_BITS ((DST_ALG_HMACSHA384 << TAG_SHIFT) + 1)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define HMACSHA512_NTAGS 2
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA512_KEY ((DST_ALG_HMACSHA512 << TAG_SHIFT) + 0)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#define TAG_HMACSHA512_BITS ((DST_ALG_HMACSHA512 << TAG_SHIFT) + 1)
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewsstruct dst_private_element {
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews unsigned short tag;
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews unsigned short length;
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews unsigned char *data;
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews};
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewstypedef struct dst_private_element dst_private_element_t;
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewsstruct dst_private {
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews unsigned short nelements;
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews dst_private_element_t elements[MAXFIELDS];
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews};
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewstypedef struct dst_private dst_private_t;
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark AndrewsISC_LANG_BEGINDECLS
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewsvoid
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewsdst__privstruct_free(dst_private_t *priv, isc_mem_t *mctx);
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewsisc_result_t
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewsdst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex,
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews isc_mem_t *mctx, dst_private_t *priv);
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewsisc_result_t
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrewsdst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv,
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews const char *directory);
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark AndrewsISC_LANG_ENDDECLS
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews#endif /* DST_DST_PARSE_H */
1e107b3d7b54de5022c3328423164e533afcc15eMark Andrews