Beispiel #1
0
void CCM_Decryption::finish(secure_vector<byte>& buffer, size_t offset)
   {
   BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");

   buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end());

   const size_t sz = buffer.size() - offset;
   byte* buf = buffer.data() + offset;

   BOTAN_ASSERT(sz >= tag_size(), "We have the tag");

   const secure_vector<byte>& ad = ad_buf();
   BOTAN_ASSERT(ad.size() % BS == 0, "AD is block size multiple");

   const BlockCipher& E = cipher();

   secure_vector<byte> T(BS);
   E.encrypt(format_b0(sz - tag_size()), T);

   for(size_t i = 0; i != ad.size(); i += BS)
      {
      xor_buf(T.data(), &ad[i], BS);
      E.encrypt(T);
      }

   secure_vector<byte> C = format_c0();

   secure_vector<byte> S0(BS);
   E.encrypt(C, S0);
   inc(C);

   secure_vector<byte> X(BS);

   const byte* buf_end = &buf[sz - tag_size()];

   while(buf != buf_end)
      {
      const size_t to_proc = std::min<size_t>(BS, buf_end - buf);

      E.encrypt(C, X);
      xor_buf(buf, X.data(), to_proc);
      inc(C);

      xor_buf(T.data(), buf, to_proc);
      E.encrypt(T);

      buf += to_proc;
      }

   T ^= S0;

   if(!same_mem(T.data(), buf_end, tag_size()))
      throw Integrity_Failure("CCM tag check failed");

   buffer.resize(buffer.size() - tag_size());
   }
Beispiel #2
0
void CCM_Encryption::finish(secure_vector<byte>& buffer, size_t offset)
   {
   BOTAN_ASSERT(buffer.size() >= offset, "Offset is sane");

   buffer.insert(buffer.begin() + offset, msg_buf().begin(), msg_buf().end());

   const size_t sz = buffer.size() - offset;
   byte* buf = buffer.data() + offset;

   const secure_vector<byte>& ad = ad_buf();
   BOTAN_ASSERT(ad.size() % BS == 0, "AD is block size multiple");

   const BlockCipher& E = cipher();

   secure_vector<byte> T(BS);
   E.encrypt(format_b0(sz), T);

   for(size_t i = 0; i != ad.size(); i += BS)
      {
      xor_buf(T.data(), &ad[i], BS);
      E.encrypt(T);
      }

   secure_vector<byte> C = format_c0();
   secure_vector<byte> S0(BS);
   E.encrypt(C, S0);
   inc(C);

   secure_vector<byte> X(BS);

   const byte* buf_end = &buf[sz];

   while(buf != buf_end)
      {
      const size_t to_proc = std::min<size_t>(BS, buf_end - buf);

      xor_buf(T.data(), buf, to_proc);
      E.encrypt(T);

      E.encrypt(C, X);
      xor_buf(buf, X.data(), to_proc);
      inc(C);

      buf += to_proc;
      }

   T ^= S0;

   buffer += std::make_pair(T.data(), tag_size());
   }
Beispiel #3
0
int
fdread(int fd, void *buf, int n)
{
	mpass::MessageEndPoint *end_point = &mpass::msg_end_point;
	mpass::Connection *conn = &end_point->conn_array[fd];
#ifdef maysam_dbg
	fprintf(stderr,"fdread on fd=%d : before is_empty\n", fd);
#endif
	while(conn->rcv_q->is_empty())
	{
#ifdef maysam_dbg
		fprintf(stderr,"fdread on fd=%d: before fdwait\n", fd);
#endif
		fdwait(fd, 'r');
	}
#ifdef maysam_dbg
	fprintf(stderr,"fdread on fd=%d: before dequeue\n", fd);
#endif

	mpass::simple_msg msg_buf(buf, n);
	conn->rcv_q->dequeue(mpass::copy_msg_from_queue, &msg_buf);
	int size = msg_buf.size;
#ifdef maysam_dbg
	fprintf(stderr,"fdread on fd=%d: after dequeue size is %d\n", fd, size);
#endif
	return size;
}
int main (int argc, char **argv) 
{ 
    zmq::context_t context(1);
    zmq::socket_t socket(context, ZMQ_SUB);
    socket.bind("ipc:///tmp/to_app.ipc");
    socket.setsockopt(ZMQ_SUBSCRIBE, "", 0); 
    
    int rxcount = 0; 
    while (!stop) { 
        zmq::message_t msg; 
        try {
            socket.recv(&msg); 
        } catch (zmq::error_t& e) { 
            exit(1); 
        }
        std::vector<uint8_t> msg_buf(msg.size()); 
        std::memcpy(msg_buf.data(), msg.data(), msg.size()); 
        
        std::string msg_str(msg_buf.begin(), msg_buf.end()); 
        
        HelperRecv recvable =
		HelperRecvBuilder()
			.fromJson(msg_str)
			.build();
        
        rxcount++; 
        printf("recv'd message [rx count = %d] \n", rxcount); 
        printf("JSON: %s \n", msg_str.c_str()); 
        printf("message payload: %s \n", recvable.payload.c_str()); 
	    printf("\n"); 
    } 
    
    return 0; 
} 
Beispiel #5
0
void LoginWindow::on_btnLogin_clicked()
{
    if (socket && socket->state() == QAbstractSocket::ConnectedState)
    {
        tamandua::message_composer msgc(tamandua::standard_message);
        msgc << command.arg(ui->txtLogin->text(), ui->txtPassword->text()).toStdString();
        tamandua::message msg = msgc();
        tamandua::message_buffer msg_buf(msg.header, msg.body);
        if (socket->write(msg_buf.get_buffer().get(), msg_buf.get_buffer_size()) == static_cast<qint64>(msg_buf.get_buffer_size()))
        {
            close();
        } else
        {
            QMessageBox::information(this, QString("Error"), QString("An error occurred while sending message! PLease try again!"));
        }
    } else
    {
        QMessageBox::information(this, QString("Error"), QString("You must be connected to server!"));
    }
}