xorp

hmac.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2011 XORP, Inc and Others
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU Lesser General Public License, Version
00008 // 2.1, June 1999 as published by the Free Software Foundation.
00009 // Redistribution and/or modification of this program under the terms of
00010 // any other version of the GNU Lesser General Public License is not
00011 // permitted.
00012 // 
00013 // This program is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00016 // see the GNU Lesser General Public License, Version 2.1, a copy of
00017 // which can be found in the XORP LICENSE.lgpl file.
00018 // 
00019 // XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00020 // http://xorp.net
00021 
00022 // $XORP: xorp/libxipc/hmac.hh,v 1.12 2008/10/02 21:57:21 bms Exp $
00023 
00024 #ifndef __LIBXIPC_HMAC_HH__
00025 #define __LIBXIPC_HMAC_HH__
00026 
00027 
00028 #include "hmac_md5.h"
00029 
00030 class HMAC {
00031 public:
00032     HMAC(const string& key) : _key(key) {}
00033     virtual ~HMAC() {}
00034     virtual size_t signature_size() const = 0;
00035     virtual const string signature(const string& message) const = 0;
00036     const string& key() const { return _key; }
00037 
00038     virtual HMAC* clone() const = 0;
00039 protected:
00040 
00041     const string _key;
00042 };
00043 
00044 class HMACMD5 : public HMAC {
00045 public:
00046     HMACMD5(const string& key) : HMAC(key) {}
00047     ~HMACMD5() {}
00048     size_t signature_size() const { return SIG_SZ; }
00049     const string signature(const string& message) const;
00050 
00051     virtual HMAC* clone() const {
00052     return new HMACMD5(key());
00053     }
00054 protected:
00055     uint32_t d8tod32(uint8_t a, uint8_t b, uint8_t c, uint8_t d) const {
00056     return (a << 24) | (b << 16) | (c << 8) | d;
00057     }
00058     static const char* SIG;
00059     static const size_t SIG_SZ;
00060 };
00061 
00062 #endif // __LIBXIPC_HMAC_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations