Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

Message.h

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: Message.h,v 1.3 2004/05/19 15:56:24 mmarsh Exp $
00008 //
00009 // $Log: Message.h,v $
00010 // Revision 1.3  2004/05/19 15:56:24  mmarsh
00011 // Added copyright and license statements.
00012 //
00013 // Revision 1.2  2003/11/04 22:04:05  mmarsh
00014 // General code cleanup.
00015 //
00016 //
00017 
00018 #ifndef __CODEX_APSS_MESSAGE_H__
00019 #define __CODEX_APSS_MESSAGE_H__
00020 
00021 #include "CODEX_Ciphers/RSA.h"
00022 #include "CODEX_Exceptions/ExceptionBase.h"
00023 #include "Types.h"
00024 #include "CODEX_ASN1/Array.h"
00025 
00026 namespace CODEX_APSS
00027 {
00028    using CODEX_Ciphers::RSASignature;
00029 
00033    class Message : public CODEX_ASN1::Base
00034    {
00035       public :
00037          Message( bool initialized ) :
00038             Base( initialized )
00039          {}
00040 
00042          virtual ~Message() {}
00043 
00045          BIGNUM * digest( const CODEX_Ciphers::HashFunction& hf ) const;
00046    };
00047 
00054    template< class MT, class ST >
00055    class SignedMessage : public Message
00056    {
00057       public :
00059          SignedMessage() : Message( false ) {}
00060 
00062          SignedMessage( const MT& message, ST signature ) :
00063             Message( true ),
00064             m_message( message ),
00065             m_signature( signature )
00066          {}
00067 
00069          SignedMessage( const SignedMessage& aMessage ) :
00070             Message( aMessage.m_initialized ),
00071             m_message( aMessage.m_message ),
00072             m_signature( aMessage.m_signature )
00073          {}
00074 
00076          virtual ~SignedMessage() {}
00077 
00079          void operator=( const SignedMessage& aMessage )
00080          {
00081             m_initialized = aMessage.m_initialized;
00082             m_message     = aMessage.m_message;
00083             m_signature   = aMessage.m_signature;
00084          }
00085 
00087          const MT&  message()   const { return m_message; }
00089          const ST&  signature() const { return m_signature; }
00090 
00092          int marshal( unsigned char ** pp ) const
00093          {
00094             int r=0;
00095             int ret=0;
00096             unsigned char * p;
00097 
00098             ret += m_message.marshal(0);
00099             ret += m_signature.marshal(0);
00100             M_ASN1_I2D_seq_total();
00101             m_message.marshal(&p);
00102             m_signature.marshal(&p);
00103             M_ASN1_I2D_finish();
00104          }
00105 
00107          void* unmarshal( void* bogus,
00108                           unsigned char ** pp,
00109                           long length )
00110          {
00111             if ( m_initialized )
00112             {
00113                return 0;
00114             }
00115             if ( (0 == pp) || (0 == *pp) )
00116             {
00117                return 0;
00118             }
00119             ASN1_CTX c;
00120             c.pp = pp;
00121             c.q = *pp;
00122             c.error = ERR_R_NESTED_ASN1_ERROR;
00123             int i;
00124 
00125             M_ASN1_D2I_Init();
00126             M_ASN1_D2I_start_sequence();
00127             M_ASN1_D2I_get(i, m_message.unmarshal);
00128             M_ASN1_D2I_get(i, m_signature.unmarshal);
00129             if ( !asn1_Finish(&c) )
00130             {
00131                return 0;
00132             }
00133             *pp=c.p;
00134             m_initialized = true;
00135             return this;
00136            err: // needed by ASN.1 macros
00137             return 0;
00138          }
00139 
00140       private :
00141          MT  m_message;
00142          ST  m_signature;
00143    };
00144 
00148    class InitMsg : public Message
00149    {
00150       public :
00152          InitMsg();
00153 
00155          InitMsg( const CODEX_ASN1::Integer& version,
00156                   const CODEX_ASN1::Integer& coordinator,
00157                   const LabelType& label );
00158 
00160          InitMsg( const InitMsg& aOther );
00161 
00163          virtual ~InitMsg() {}
00164 
00166          void operator=( const InitMsg& aOther );
00167 
00172          const CODEX_ASN1::Integer& version() const { return m_version; }
00173 
00175          const CODEX_ASN1::Integer& coordinator() const
00176          {
00177             return m_coordinator;
00178          }
00179 
00184          const LabelType& label() const { return m_label; }
00185 
00187          int marshal( unsigned char ** pp ) const;
00189          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00190 
00191       private :
00192          CODEX_ASN1::Integer  m_version;
00193          CODEX_ASN1::Integer  m_coordinator;
00194          LabelType            m_label;
00195    };
00197    typedef SignedMessage< InitMsg, RSASignature >  SignedInitMsg;
00198 
00203    class EstablishMsg : public Message
00204    {
00205       public :
00207          EstablishMsg();
00208 
00210          EstablishMsg( const CODEX_ASN1::Integer& version,
00211                        const SublabelType& sublabel,
00212                        const CODEX_ASN1::Integer& establisher,
00213                        const CODEX_ASN1::Integer& recipient,
00214                        const ShareType& shares );
00215 
00217          EstablishMsg( const EstablishMsg& aOther );
00218 
00220          virtual ~EstablishMsg() {}
00221 
00223          void operator=( const EstablishMsg& aOther );
00224 
00226          const CODEX_ASN1::Integer& version() const { return m_version; }
00227 
00229          const SublabelType& sublabel() const { return m_sublabel; }
00230 
00232          const CODEX_ASN1::Integer& establisher() const
00233          {
00234             return m_establisher;
00235          }
00236 
00238          const CODEX_ASN1::Integer& recipient() const { return m_recipient; }
00239 
00241          const ShareType& shares() const { return m_shares; }
00242 
00243          int marshal( unsigned char ** pp ) const;
00244          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00245 
00246       private :
00247          CODEX_ASN1::Integer  m_version;
00248          SublabelType         m_sublabel;
00249          CODEX_ASN1::Integer  m_establisher;
00250          CODEX_ASN1::Integer  m_recipient;
00251          ShareType            m_shares;
00252    };
00254    typedef SignedMessage< EstablishMsg, RSASignature >  SignedEstablishMsg;
00255 
00259    class EstablishedMsg : public Message
00260    {
00261       public :
00263          EstablishedMsg();
00264 
00266          EstablishedMsg( const EstablishMsg& request );
00267 
00269          EstablishedMsg( const EstablishedMsg& aOther );
00270 
00272          virtual ~EstablishedMsg() {}
00273 
00275          void operator=( const EstablishedMsg& aOther );
00276 
00278          const CODEX_ASN1::Integer& version() const { return m_version; }
00279 
00281          const SublabelType& sublabel() const { return m_sublabel; }
00282 
00284          const CODEX_ASN1::Integer& recipient() const { return m_recipient; }
00285 
00287          const CODEX_ASN1::Integer& establisher() const
00288          {
00289             return m_establisher;
00290          }
00291 
00292          int marshal( unsigned char ** pp ) const;
00293          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00294 
00295       private :
00296          CODEX_ASN1::Integer  m_version;
00297          SublabelType         m_sublabel;
00298          CODEX_ASN1::Integer  m_recipient;
00299          CODEX_ASN1::Integer  m_establisher;
00300    };
00302    typedef SignedMessage< EstablishedMsg, RSASignature >  SignedEstablishedMsg;
00304    typedef CODEX_ASN1::Array< SignedEstablishedMsg >      EstablishedArray;
00305 
00310    class ContributeMsg : public Message
00311    {
00312       public :
00314          ContributeMsg();
00315 
00317          ContributeMsg( const CODEX_ASN1::Integer& version,
00318                         const CODEX_ASN1::Integer& coordinator,
00319                         const CODEX_ASN1::Integer& contributor,
00320                         const EstablishedArray& evidence );
00321 
00323          ContributeMsg( const ContributeMsg& aOther );
00324 
00326          virtual ~ContributeMsg() {}
00327 
00329          void operator=( const ContributeMsg& aOther );
00330 
00332          const CODEX_ASN1::Integer& version() const { return m_version; };
00333 
00335          const CODEX_ASN1::Integer& coordinator() const
00336          {
00337             return m_coordinator;
00338          }
00339 
00341          const CODEX_ASN1::Integer& contributor() const
00342          {
00343             return m_contributor;
00344          }
00345 
00347          const EstablishedArray& evidence() const { return m_evidence; }
00348 
00350          int marshal( unsigned char ** pp ) const;
00352          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00353 
00354       private :
00355          CODEX_ASN1::Integer   m_version;
00356          CODEX_ASN1::Integer   m_coordinator;
00357          CODEX_ASN1::Integer   m_contributor;
00358          EstablishedArray      m_evidence;
00359    };
00361    typedef SignedMessage< ContributeMsg, RSASignature >  SignedContributeMsg;
00362 
00367    class ComputeMsg : public Message
00368    {
00369       public :
00371          const static unsigned int  NumShares = ShareType::NumShares;
00372 
00374          ComputeMsg();
00375 
00377          ComputeMsg( const CODEX_ASN1::Integer& coordinator,
00378                      const SublabelType subshareLabels[ NumShares ] );
00379 
00381          ComputeMsg( const ComputeMsg& aOther );
00382 
00384          virtual ~ComputeMsg() {}
00385 
00387          void operator=( const ComputeMsg& aOther );
00388 
00390          const CODEX_ASN1::Integer& coordinator() const
00391          {
00392             return m_coordinator;
00393          }
00394 
00402          const SublabelType& subshareLabel( unsigned int i ) const
00403          {
00404             if ( i >= NumShares )
00405             {
00406                throw CODEX_Exceptions::IllegalIndexException( __FILE__ ,
00407                                                               __LINE__ );
00408             }
00409             return m_subshareLabels[ i ];
00410          }
00411 
00413          int marshal( unsigned char ** pp ) const;
00415          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00416 
00417       private :
00418          CODEX_ASN1::Integer  m_coordinator;
00419          SublabelType         m_subshareLabels[ NumShares ];
00420    };
00422    typedef SignedMessage< ComputeMsg, RSASignature >  SignedComputeMsg;
00423 
00429    class ComputedMsg : public Message
00430    {
00431       public :
00433          ComputedMsg();
00434 
00436          ComputedMsg( const LabelType& shareLabel,
00437                       const CODEX_ASN1::Integer& computor );
00438 
00440          ComputedMsg( const ComputedMsg& aOther );
00441 
00443          virtual ~ComputedMsg() {}
00444 
00446          void operator=( const ComputedMsg& aOther );
00447 
00449          const LabelType& shareLabel() const { return m_shareLabel; }
00450 
00452          const CODEX_ASN1::Integer& computor() const { return m_computor; };
00453 
00455          int marshal( unsigned char ** pp ) const;
00457          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00458 
00459       private :
00460          LabelType            m_shareLabel;
00461          CODEX_ASN1::Integer  m_computor;
00462    };
00464    typedef SignedMessage< ComputedMsg, RSASignature >  SignedComputedMsg;
00466    typedef CODEX_ASN1::Array< SignedComputedMsg >      ComputedArray;
00467 
00472    class FinishedMsg : public Message
00473    {
00474       public :
00476          FinishedMsg();
00477 
00479          FinishedMsg( const CODEX_ASN1::Integer& version,
00480                       const CODEX_ASN1::Integer& coordinator,
00481                       const ComputedArray& evidence );
00482 
00484          FinishedMsg( const FinishedMsg& aOther );
00485 
00487          virtual ~FinishedMsg() {}
00488 
00490          void operator=( const FinishedMsg& aOther );
00491 
00493          const CODEX_ASN1::Integer& version() const { return m_version; };
00494 
00496          const CODEX_ASN1::Integer& coordinator() const
00497          {
00498             return m_coordinator;
00499          }
00500 
00505          const ComputedArray& evidence() const { return m_evidence; }
00506 
00508          int marshal( unsigned char ** pp ) const;
00510          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00511 
00512       private :
00513          CODEX_ASN1::Integer  m_version;
00514          CODEX_ASN1::Integer  m_coordinator;
00515          ComputedArray        m_evidence;
00516    };
00518    typedef SignedMessage< FinishedMsg, RSASignature >  SignedFinishedMsg;
00519 
00523    class RecoverMsg : public Message
00524    {
00525       public :
00527          RecoverMsg();
00528 
00530          RecoverMsg( const CODEX_ASN1::Integer& version,
00531                      const SublabelType& sublabel,
00532                      const CODEX_ASN1::Integer& requester,
00533                      const CODEX_ASN1::Integer& responder );
00534 
00536          RecoverMsg( const RecoverMsg& aOther );
00537 
00539          virtual ~RecoverMsg() {}
00540 
00542          void operator=( const RecoverMsg& aOther );
00543 
00545          const CODEX_ASN1::Integer& version() const { return m_version; };
00546 
00548          const SublabelType& sublabel() const { return m_sublabel; }
00549 
00551          const CODEX_ASN1::Integer& requester() const { return m_requester; }
00552 
00554          const CODEX_ASN1::Integer& responder() const { return m_responder; }
00555 
00557          int marshal( unsigned char ** pp ) const;
00559          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00560 
00561       private :
00562          CODEX_ASN1::Integer  m_version;
00563          SublabelType         m_sublabel;
00564          CODEX_ASN1::Integer  m_requester;
00565          CODEX_ASN1::Integer  m_responder;
00566    };
00568    typedef SignedMessage< RecoverMsg, RSASignature >  SignedRecoverMsg;
00569 
00574    class RecoveredMsg : public Message
00575    {
00576       public :
00578          RecoveredMsg();
00579 
00581          RecoveredMsg( const RecoverMsg& request,
00582                        const ShareType& shareset );
00583 
00585          RecoveredMsg( const RecoveredMsg& aOther );
00586 
00588          virtual ~RecoveredMsg() {}
00589 
00591          void operator=( const RecoveredMsg& aOther );
00592 
00594          const CODEX_ASN1::Integer& version() const { return m_version; };
00595 
00597          const SublabelType& sublabel() const { return m_sublabel; }
00598 
00600          const CODEX_ASN1::Integer& responder() const
00601          {
00602             return m_responder;
00603          }
00604 
00609          const ShareType& shares() const { return m_shares; }
00610 
00612          const CODEX_ASN1::Integer& requester() const
00613          {
00614             return m_requester;
00615          }
00616 
00618          int marshal( unsigned char ** pp ) const;
00620          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00621 
00622       private :
00623          CODEX_ASN1::Integer  m_version;
00624          SublabelType         m_sublabel;
00625          CODEX_ASN1::Integer  m_responder;
00626          ShareType            m_shares;
00627          CODEX_ASN1::Integer  m_requester;
00628    };
00630    typedef SignedMessage< RecoveredMsg, RSASignature >  SignedRecoveredMsg;
00631 
00639    enum MessageType
00640    {
00641       kInitMsg,
00642       kEstablishMsg,
00643       kEstablishedMsg,
00644       kContributeMsg,
00645       kComputeMsg,
00646       kComputedMsg,
00647       kFinishedMsg,
00648       kRecoverMsg,
00649       kRecoveredMsg,
00650       kBadRequest
00651    };
00652 
00657    const unsigned char SignatureMask = 0x80;
00658 }
00659 
00660 #endif /* __CODEX_APSS_MESSAGE_H__ */

Generated on Wed Jun 2 16:32:55 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18