/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifdef HMAC_MD5
#ifndef LINT
static const char rcsid[] = "$Header: /proj/cvs/prod/libbind/dst/hmac_link.c,v 1.8 2007/09/24 17:18:25 each Exp $";
#endif
/*
* Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
*
* Permission to use, copy modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THE SOFTWARE.
*/
/*%
* This file contains an implementation of the HMAC-MD5 algorithm.
*/
#include "port_before.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <resolv.h>
#include "dst_internal.h"
#ifdef USE_MD5
# ifndef HAVE_MD5
# include "md5.h"
# else
# ifdef SOLARIS2
# endif
# endif
# ifndef _MD5_H_
# endif
#endif
#include "port_after.h"
typedef struct hmackey {
} HMAC_Key;
/**************************************************************************
* dst_hmac_md5_sign
* Call HMAC signing functions to sign a block of data.
* There are three steps to signing, INIT (initialize structures),
* UPDATE (hash (more) data), FINAL (generate a signature). This
* routine performs one or more of these steps.
* Parameters
* priv_key key to use for signing.
* context the context to be used in this digest
* data data to be signed.
* len length in bytes of data.
* signature location to store signature.
* sig_len size of the signature location
* returns
* N Success on SIG_MODE_FINAL = returns signature length in bytes
* 0 Success on SIG_MODE_INIT and UPDATE
* <0 Failure
*/
static int
{
int sign_len = 0;
return (-1);
if (mode & SIG_MODE_INIT)
else if (context)
return (-1);
if (mode & SIG_MODE_INIT) {
}
if (mode & SIG_MODE_FINAL) {
return (SIGN_FINAL_FAILURE);
/* perform outer MD5 */
}
else {
return (-1);
}
return (sign_len);
}
/**************************************************************************
* dst_hmac_md5_verify()
* Calls HMAC verification routines. There are three steps to
* verification, INIT (initialize structures), UPDATE (hash (more) data),
* FINAL (generate a signature). This routine performs one or more of
* these steps.
* Parameters
* dkey key to use for verify.
* data data signed.
* len length in bytes of data.
* signature signature.
* sig_len length in bytes of signature.
* returns
* 0 Success
* <0 Failure
*/
static int
{
return (-1);
if (mode & SIG_MODE_INIT)
else if (context)
return (-1);
if (mode & SIG_MODE_INIT) {
}
if (mode & SIG_MODE_FINAL) {
return (VERIFY_FINAL_FAILURE);
/* perform outer MD5 */
return (VERIFY_FINAL_FAILURE);
}
else {
return (-1);
}
return (0);
}
/**************************************************************************
* dst_buffer_to_hmac_md5
* Converts key from raw data to an HMAC Key
* This function gets in a pointer to the data
* Parameters
* hkey the HMAC key to be filled in
* key the key in raw format
* keylen the length of the key
* Return
* 0 Success
* <0 Failure
*/
static int
{
int i;
return (-1);
return (-2);
/* if key is longer than HMAC_LEN bytes reset it to key=MD5(key) */
}
/* start out by storing key in pads */
/* XOR key with hk_ipad and opad values */
for (i = 0; i < HMAC_LEN; i++) {
}
return (1);
}
/**************************************************************************
* dst_hmac_md5_key_to_file_format
* Encodes an HMAC Key into the portable file format.
* Parameters
* hkey HMAC KEY structure
* buff output buffer
* buff_len size of output buffer
* Return
* 0 Failure - null input hkey
* -1 Failure - not enough space in output area
* N Success - Length of data returned in buff
*/
static int
const int buff_len)
{
char *bp;
return (0);
/*
* Using snprintf() would be so much simpler here.
*/
return (-1); /*%< no OR not enough space in output area */
/* write file header */
for (i = 0; i < HMAC_LEN; i++)
for (i = HMAC_LEN - 1; i >= 0; i--)
if (key[i] != 0)
break;
key_len = i + 1;
return (-1);
if (len < 0)
return (-1);
return (-1);
*(bp++) = '\n';
*bp = '\0';
}
/**************************************************************************
* dst_hmac_md5_key_from_file_format
* Converts contents of a key file into an HMAC key.
* Parameters
* hkey structure to put key into
* buff buffer containing the encoded key
* buff_len the length of the buffer
* Return
* n >= 0 Foot print of the key converted
* n < 0 Error in conversion
*/
static int
const int buff_len)
{
* it should probably be fixed rather than doing
* this
*/
return (-2);
return (-1);
if (!dst_s_verify_str(&p, "Key: "))
return (-3);
return (-4);
return (-5);
return (-6);
}
return (0);
}
/*%
* dst_hmac_md5_to_dns_key()
* function to extract hmac key from DST_KEY structure
* intput:
* in_key: HMAC-MD5 key
* output:
* out_str: buffer to write ot
* out_len: size of output buffer
* returns:
* number of bytes written to output buffer
*/
static int
const int out_len)
{
int i;
return (-1);
for (i = 0; i < in_key->dk_key_size; i++)
return (i);
}
/**************************************************************************
* dst_hmac_md5_compare_keys
* Compare two keys for equality.
* Return
* 0 The keys are equal
* NON-ZERO The keys are not equal
*/
static int
{
}
/**************************************************************************
* dst_hmac_md5_free_key_structure
* Frees all (none) dynamically allocated structures in hkey
*/
static void *
{
return (NULL);
}
/***************************************************************************
* dst_hmac_md5_generate_key
* Creates a HMAC key of size size with a maximum size of 63 bytes
* generating a HMAC key larger than 63 bytes makes no sense as that key
* is digested before use.
*/
static int
{
(void)key;
(void)nothing;
return (-1);
}
/*%
* dst_hmac_md5_init() Function to answer set up function pointers for HMAC
* related functions
*/
int
{
return (1);
return (0);
return (1);
}
#else
int
return (0);
}
#endif
/*! \file */