~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/crypt/crypt-dull.cc

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 /*
  2  * crypt-dull.cc --
  3  *
  4  *      FIXME: This file needs a description here.
  5  *
  6  * Copyright (c) 1995-2002 The Regents of the University of California.
  7  * All rights reserved.
  8  *
  9  * Redistribution and use in source and binary forms, with or without
 10  * modification, are permitted provided that the following conditions are met:
 11  *
 12  * A. Redistributions of source code must retain the above copyright notice,
 13  *    this list of conditions and the following disclaimer.
 14  * B. Redistributions in binary form must reproduce the above copyright notice,
 15  *    this list of conditions and the following disclaimer in the documentation
 16  *    and/or other materials provided with the distribution.
 17  * C. Neither the names of the copyright holders nor the names of its
 18  *    contributors may be used to endorse or promote products derived from this
 19  *    software without specific prior written permission.
 20  *
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 22  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  */
 33 
 34 static const char rcsid[] =
 35     "@(#) $Header: /usr/mash/src/repository/mash/mash-1/crypt/crypt-dull.cc,v 1.7 2003/11/19 19:20:26 aswan Exp $";
 36 
 37 #include "crypt/crypt.h"
 38 #include "rtp/inet.h"
 39 #include "rtp/rtp.h"
 40 
 41 /*
 42  * A simple XOR data scrambler.  This is module is provided for test
 43  * purposes and to illustrate the extensibility of the encryption interface.
 44  *
 45  * This algorithm is trivial to crack using an obvious plaintext
 46  * attack.  It will only protect against accidental eavesdropping.
 47  */
 48 class CryptDull : public Crypt {
 49     public:
 50         CryptDull();
 51         ~CryptDull();
 52         virtual int install_key(const u_int8_t* key);
 53         virtual u_char* Encrypt(const u_char* in, int& len);
 54         virtual int Decrypt(const u_char* in, int len, u_char* out);
 55     protected:
 56         void crypt(const u_int32_t* in, u_int32_t* out, int nw);
 57         u_int32_t key_;
 58         u_char* wrkbuf_;
 59 };
 60 
 61 static class CryptDullDataClass : public TclClass {
 62     public:
 63         CryptDullDataClass() : TclClass("Crypt/Data/DULL") {}
 64         TclObject* create(int /* argc */, const char*const* /* argv */) {
 65                 return (new CryptDull);
 66         }
 67 } cld_ctrl;
 68 
 69 static class CryptDullCtrlClass : public TclClass {
 70     public:
 71         CryptDullCtrlClass() : TclClass("Crypt/Control/DULL") {}
 72         TclObject* create(int /* argc */, const char*const* /* argv */) {
 73                 return (new CryptDull);
 74         }
 75 } cls_data;
 76 
 77 CryptDull::CryptDull()
 78 {
 79 
 80         /* enough extra space for padding and RTCP 4-byte random header */
 81         wrkbuf_ = new u_char[RTP_MTU + 8 + 4];
 82 }
 83 
 84 CryptDull::~CryptDull()
 85 {
 86         delete wrkbuf_;
 87 }
 88 
 89 int CryptDull::install_key(const u_int8_t* key)
 90 {
 91         /* net order */
 92         key_ = *(u_int32_t*)key;
 93         return (0);
 94 }
 95 
 96 void CryptDull::crypt(const u_int32_t* in, u_int32_t* out, int nw)
 97 {
 98         u_int32_t k = key_;
 99         for (int i = 0; i < nw; ++i)
100                 out[i] = in[i] ^ k;
101 }
102 
103 u_char* CryptDull::Encrypt(const u_char* in, int& len)
104 {
105         /*
106          * assume input is word-aligned and we can read
107          * past end to next longword boundary
108          */
109         crypt((const u_int32_t*)in, (u_int32_t*)wrkbuf_, (len + 3) >> 2);
110         return (wrkbuf_);
111 }
112 
113 int CryptDull::Decrypt(const u_char* in, int len, u_char* out)
114 {
115         /*
116          * assume input/output is word-aligned and we can read/write
117          * past end to next longword boundary
118          */
119         crypt((const u_int32_t*)in, (u_int32_t*)out, (len + 3) >> 2);
120         return (len);
121 }
122 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.