Example #1
0
int crypto_stream_skinny128128ecb_avx2(
  unsigned char *out,
  unsigned char *in,
  unsigned long long inlen,
  const unsigned char *k
) 
{
  int i, j;
  u256 rk[40][16];
  u256 x[32];
  u256 key;

  if (!inlen) return 0;

  key_schedule(k, rk);

  while(inlen >= 1024){
      pack_message(x, in);
      encrypt_64blocks(x, rk);
      unpack_and_store_message(out, x);
    
    inlen -= 1024;
    in += 1024;
    out += 1024;
  }

  return 0;
}
Example #2
0
void HeartBeats::run(){
    int length = pack_message(HEART_BEATS,NULL,0,SendBuffer);
    int status;
    LinkC_Debug("UDP Heart Beats",LINKC_STARTED);
    while(1){
        status = Dest.Send_msg(SendBuffer,length,0);
        if(status == LINKC_FAILURE){
            LinkC_Debug("Heart Beats",LINKC_WARNING);
            emit SendError(status);
        }
        sleep(HEART_BEATS_TIME);
    }
}
Example #3
0
void HeartBeats::run(){
    int length = pack_message(HEART_BEATS,NULL,0,SendBuffer);
    int status;
    printf("Debug >> Heart Beats\t= [STARTED]\n");
    while(1){
        status = Dest.Send_msg(SendBuffer,length,0);
        if(status == LINKC_FAILURE){
            printf("Debug >> Heart Beats\t= [ERROR]\n");
            emit SendError(status);
        }
        sleep(HEART_BEATS_TIME);
    }
}
Example #4
0
/* nao contemplei os timeouts, acho que e preciso apanhalos com sinais */
int read_message(char* buf)
{
    STOP=FALSE;
    int res=0;
    printf("\n- - - receiving message - - -\n");
    while (STOP==FALSE) {
        res = read(private_tio_fd,buf,256);

        if (res>0 && buf[res-1] == 0)
            STOP=TRUE;

        buf[res]=0;
        printf("%s",buf);
        total_read += res;
    }
    printf("\n- - - end of received message - - -\n");

    //send message received confirmation
    pack_message();
    //write_message();
    printf("- - - confirmation received - - -\n");

    return 0;
}
Example #5
0
/* 主函数 */
int main(int argc, char *argv[])
{
    Message msg; /* 定义一个Message结构体 */
    char buff[1024]; /* 定义缓冲区 */
    struct sockaddr_in server_addr; /* 定义服务器的结构体 */
    struct hostent *host; /* 定义服务器地址 */
    int ret; /* 保存线程创建的返回值 */
    pthread_t id; /* 线程id */

    /* 查询服务器端的地址 */
    if (argc != 2)
    {
        fprintf(stderr, "Usage:%s hostname \a\n", argv[0]);
        exit(1);
    }
    if ((host = gethostbyname(argv[1])) == NULL)
    {
        fprintf(stderr, "Gethostname error\n");
        exit(1);
    }

    /* 调用socket函数创建一个TCP协议套接口 */
    if ((sockfd = socket(AF_INET,SOCK_STREAM, 0)) == -1)
    {
        fprintf(stderr, "Socket Error:%s\a\n", strerror(errno));
        exit(1);
    }

    /* 填充服务器端的资料 */
    bzero(&server_addr, sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(port);
    server_addr.sin_addr = *((struct in_addr *) host->h_addr);

    /* 连接服务器 */
    if (connect(sockfd, (struct sockaddr *) (&server_addr),
            sizeof(struct sockaddr)) == -1)
    {
        fprintf(stderr, "Connect Error:%s\a\n", strerror(errno));
        exit(1);
    }

    /* 互斥锁 */
    pthread_mutex_init(&mutex, NULL); /* 初始化互斥锁 */
    ret = pthread_create(&id, NULL, (void *) read_msg, NULL); /* 创建一个信线程来读取服务器端发送的信息 */
    if (ret != 0)
    {
        printf("Create pthread error!\n");
        exit(1);
    }

    login(); /* 打印欢迎信息 */
    /* 死循环,开始聊天 */
    while (1)
    {
        printf("Please enter your command, input hlp view the help\n");
        bzero(buff, sizeof(buff)); /* 清空缓冲区 */
        fgets(buff, 1024, stdin); /* 将输入的数据存到buff中 */
        msg.action = check_putin(buff); /* 字符解析,返回到action中 */
        if (msg.action == WRONG_CMD) /* 当输入的为错误的命令时 */
        {
            printf("Bad Command\n");
            continue;
        }

        if (pack_message(msg.action, &msg, buff) == 1) /* 返回1时跳入下一次循环 */
        {
            continue;
        }

        if (msg.action == HELP) /* 当命令为帮助时,不将数据打包 */
        {
            login();
            continue;
        }
        if (msg.action == EXIT) /* 当命令为退出时,关闭进程 */
        {
            exit(0);
        }

        write(sockfd, &msg, sizeof(msg)); /* 发送数据包 */

        if (msg.action == REGIST) /* 注册结束后清空数据包 */
        {
            bzero(&msg.message, sizeof(msg.message));
            bzero(&msg.user, sizeof(msg.user));
            bzero(&msg.target, sizeof(msg.target));
            bzero(&msg.password, sizeof(msg.password));
        }
        sleep(1);
    }
    close(sockfd);
    exit(0);
}
Example #6
0
template <class T, class ... Args> std::string create_packet(T type, Args ... args)
{
    return pack_message(type, to_string(args...));
}