Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

ZrtpPacketDHPart.cxx

Go to the documentation of this file.
00001 /*
00002   Copyright (C) 2006-2007 Werner Dittmann
00003 
00004   This program is free software: you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation, either version 3 of the License, or
00007   (at your option) any later version.
00008 
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details.
00013 
00014   You should have received a copy of the GNU General Public License
00015   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 /*
00019  * Authors: Werner Dittmann <Werner.Dittmann@t-online.de>
00020  */
00021 
00022 #include <libzrtpcpp/ZrtpPacketDHPart.h>
00023 
00024 
00025 ZrtpPacketDHPart::ZrtpPacketDHPart(SupportedPubKeys pkt) {
00026     DEBUGOUT((fprintf(stdout, "Creating DHPart packet without data\n")));
00027 #if 0
00028     int length = sizeof(DHPart_t) + sizeof(zrtpPacketHeader_t) + CRC_SIZE + ((pkt == Dh3072) ? 384 : 512);
00029 
00030     void* allocated = &data;
00031     memset(allocated, 0, length);
00032 
00033     pktype = pkt;
00034 
00035     zrtpHeader = (zrtpPacketHeader_t *)&((DHPartPacket_t *)allocated)->hdr;     // the standard header
00036     pv = ((uint8_t *)allocated) + sizeof(zrtpPacketHeader_t);    // point to the public key value
00037     DHPartHeader = (DHPart_t *)(pv + ((pkt == Dh3072) ? 384 : 512));
00038 
00039     setZrtpId();
00040     // Subtract one to exclude the CRC word from length in ZRTP message 
00041     setLength((length / 4) - 1);
00042     // setLength(DHPART_LENGTH + MESSAGE_LENGTH + ((pkt == Dh3072) ? 96 : 128));
00043 #else
00044     int length = sizeof(DHPartPacket_t) + CRC_SIZE + ((pkt == Dh3072) ? 384 : 512);
00045 
00046     void* allocated = &data;
00047     memset(allocated, 0, length);
00048 
00049     pktype = pkt;
00050 
00051     zrtpHeader = (zrtpPacketHeader_t *)&((DHPartPacket_t *)allocated)->hdr;     // the standard header
00052     DHPartHeader = (DHPart_t *)&((DHPartPacket_t *)allocated)->dhPart;
00053     pv = ((uint8_t *)allocated) + sizeof(DHPartPacket_t);    // point to the public key value
00054 
00055     setZrtpId();
00056     // Subtract one to exclude the CRC word from length in ZRTP message 
00057     setLength((length / 4) - 1);
00058 #endif
00059 }
00060 
00061 ZrtpPacketDHPart::ZrtpPacketDHPart(uint8_t *data) {
00062     DEBUGOUT((fprintf(stdout, "Creating DHPart packet from data\n")));
00063 #if 0
00064     zrtpHeader = (zrtpPacketHeader_t *)&((DHPartPacket_t *)data)->hdr;  // the standard header
00065 
00066     int16_t len = getLength();
00067     DEBUGOUT((fprintf(stdout, "DHPart length: %d\n", len)));
00068     SupportedPubKeys pkt;
00069     if (len == 109) {
00070         pkt = Dh3072;
00071     }
00072     else if (len == 141) {
00073         pkt = Dh4096;
00074     }
00075     else {
00076         fprintf(stderr, "Wrong DHPart length: %d\n", len);
00077         pv = NULL;
00078         return;
00079     }
00080     pv = data + sizeof(zrtpPacketHeader_t);
00081     DHPartHeader = (DHPart_t *)(data + sizeof(zrtpPacketHeader_t) + ((pkt == Dh3072) ? 384 : 512));
00082     pktype = pkt;
00083 #else
00084     zrtpHeader = (zrtpPacketHeader_t *)&((DHPartPacket_t *)data)->hdr;  // the standard header
00085     DHPartHeader = (DHPart_t *)&((DHPartPacket_t *)data)->dhPart;
00086 
00087     int16_t len = getLength();
00088     DEBUGOUT((fprintf(stdout, "DHPart length: %d\n", len)));
00089     SupportedPubKeys pkt;
00090     if (len == 109) {
00091         pkt = Dh3072;
00092     }
00093     else if (len == 141) {
00094         pkt = Dh4096;
00095     }
00096     else {
00097         fprintf(stderr, "Wrong DHPart length: %d\n", len);
00098         pv = NULL;
00099         return;
00100     }
00101     pv = data + sizeof(DHPartPacket_t);    // point to the public key value
00102     pktype = pkt;
00103 #endif
00104 }
00105 
00106 ZrtpPacketDHPart::~ZrtpPacketDHPart() {
00107     DEBUGOUT((fprintf(stdout, "Deleting DHPart packet: alloc: %x\n", allocated)));
00108 }

© sourcejam.com 2005-2008