repo_name
stringlengths
5
122
path
stringlengths
3
232
text
stringlengths
6
1.05M
minnonymous/tcpcrypt
user/src/cygwin.c
<reponame>minnonymous/tcpcrypt #include <stdlib.h> #include <string.h> #include <stdint.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <winsock2.h> #include <windows.h> #include <iphlpapi.h> #include "inc.h" #include "tcpcrypt_divert.h" #include "tcpcryptd.h" #include <windivert.h> #define MAC_SIZE 14 static int _s; static divert_cb _cb; struct packet { unsigned char p_buf[2048]; int p_len; struct packet *p_next; } _outbound; extern int do_divert_open(void); extern int do_divert_read(int s, void *buf, int len); extern int do_divert_write(int s, void *buf, int len); extern void do_divert_close(int s); int divert_open(int port, divert_cb cb) { _s = do_divert_open(); _cb = cb; return _s; } void divert_close(void) { do_divert_close(_s); } static void do_divert_next_packet(unsigned char *buf, int rc) { int verdict; int flags = 0; struct ip *iph = (struct ip*) &buf[MAC_SIZE]; int len; PDIVERT_ADDRESS addr = (PDIVERT_ADDRESS)buf; if (rc < MAC_SIZE) errx(1, "short read %d", rc); if (addr->Direction == WINDIVERT_DIRECTION_INBOUND) flags |= DF_IN; // XXX ethernet padding on short packets? (46 byte minimum) len = rc - MAC_SIZE; if (len > ntohs(iph->ip_len)) { xprintf(XP_ALWAYS, "Trimming from %d to %d\n", len, ntohs(iph->ip_len)); len = ntohs(iph->ip_len); } verdict = _cb(iph, len, flags); switch (verdict) { case DIVERT_MODIFY: rc = ntohs(iph->ip_len) + MAC_SIZE; /* fallthrough */ case DIVERT_ACCEPT: flags = do_divert_write(_s, buf, rc); if (flags == -1) err(1, "write()"); if (flags != rc) errx(1, "wrote %d/%d", flags, rc); break; case DIVERT_DROP: break; default: abort(); break; } } void divert_next_packet(int s) { unsigned char buf[2048]; int rc; rc = do_divert_read(_s, buf, sizeof(buf)); if (rc == -1) err(1, "read()"); if (rc == 0) errx(1, "EOF"); do_divert_next_packet(buf, rc); } void divert_inject(void *data, int len) { struct packet *p, *p2; unsigned short *et; struct ip *iph = (struct ip*) data; p = malloc(sizeof(*p)); if (!p) err(1, "malloc()"); memset(p, 0, sizeof(*p)); // XXX: for divert, we can just zero the ethhdr, which contains the // DIVERT_ADDRESS. A zeroed address usually gives the desired // result. /* payload */ p->p_len = len + MAC_SIZE; if (p->p_len > sizeof(p->p_buf)) errx(1, "too big (divert_inject)"); memcpy(&p->p_buf[MAC_SIZE], data, len); /* add to list */ p2 = &_outbound; if (p2->p_next) p2 = p2->p_next; p2->p_next = p; } void divert_cycle(void) { struct packet *p = _outbound.p_next; while (p) { struct packet *next = p->p_next; do_divert_next_packet(p->p_buf, p->p_len); free(p); p = next; } _outbound.p_next = NULL; } void drop_privs(void) { }
minnonymous/tcpcrypt
user/util/tcs.c
<gh_stars>100-1000 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> #include <stdint.h> #include "src/inc.h" #include "src/tcpcryptd.h" #include "src/tcpcrypt.h" #include "src/tcpcrypt_ctl.h" #include "src/tcpcrypt_strings.h" static const char *_bind_ip = "0.0.0.0"; enum { TYPE_CLIENT = 0, TYPE_SERVER, TYPE_RAW, }; enum { FLAG_HELLO = 1, }; struct sock { int s; int type; int dead; time_t added; struct sockaddr_in peer; int port; int flags; struct sock *next; } _socks; struct client { int sport; int dport; int flags; struct in_addr ip; time_t added; struct client *next; } _clients; static struct sock *add_sock(int s) { struct sock *sock = malloc(sizeof(*sock)); if (!sock) err(1, "malloc()"); memset(sock, 0, sizeof(*sock)); sock->s = s; sock->added = time(NULL); sock->next = _socks.next; _socks.next = sock; return sock; } static void add_server(int port) { int s; struct sockaddr_in s_in; struct sock *sock; int one = 1; if ((s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) err(1, "socket()"); if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1) err(1, "setsockopt()"); memset(&s_in, 0, sizeof(s_in)); s_in.sin_addr.s_addr = inet_addr(_bind_ip); s_in.sin_port = htons(port); if (bind(s, (struct sockaddr*) &s_in, sizeof(s_in)) == -1) err(1, "bind()"); if (listen(s, 5) == -1) err(1, "listen()"); sock = add_sock(s); sock->type = TYPE_SERVER; sock->port = port; } static void add_sniffer(void) { int s; struct sock *sock; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)) == -1) err(1, "socket()"); sock = add_sock(s); sock->type = TYPE_RAW; } static void find_client(struct sock *s) { struct client *c = &_clients; while (c->next) { struct client *next = c->next; struct client *del = NULL; if (next->dport == s->port && next->sport == ntohs(s->peer.sin_port)) { s->flags = next->flags; del = next; } if ((time(NULL) - next->added) > 10) del = next; if (del) { c->next = next->next; free(del); } else c = next; } } static void handle_server(struct sock *s) { struct sockaddr_in s_in; socklen_t len = sizeof(s_in); int dude; struct sock *d; dude = accept(s->s, (struct sockaddr*) &s_in, &len); if (dude == -1) { perror("accept()"); return; } d = add_sock(dude); memcpy(&d->peer, &s_in, sizeof(d->peer)); d->port = s->port; find_client(d); } static void handle_client(struct sock *s) { char buf[1024]; int rc; int got = -1; int i; int crypt = 0; unsigned int len; struct tm *tm; time_t t; len = sizeof(buf); rc = tcpcrypt_getsockopt(s->s, IPPROTO_TCP, TCP_CRYPT_SESSID, buf, &len); crypt = rc != -1; rc = read(s->s, buf, sizeof(buf) - 1); if (rc <= 0) { s->dead = 1; return; } buf[rc] = 0; s->dead = 1; for (i = 0; i < sizeof(REQS) / sizeof(*REQS); i++) { if (strcmp(buf, REQS[i]) == 0) { got = i; break; } } if (got == -1) return; snprintf(buf, sizeof(buf), "%s%d", TEST_REPLY, s->flags); rc = strlen(buf); if (write(s->s, buf, rc) != rc) return; t = time(NULL); tm = localtime(&t); strftime(buf, sizeof(buf), "%m/%d/%y %H:%M:%S", tm); printf("[%s] GOT %s:%d - %4d [MSG %d] crypt %d flags %d\n", buf, inet_ntoa(s->peer.sin_addr), ntohs(s->peer.sin_port), s->port, got, crypt, s->flags); s->dead = 1; } static void found_crypt(struct ip *ip, struct tcphdr *th) { struct client *c = malloc(sizeof(*c)); if (!c) err(1, "malloc()"); memset(c, 0, sizeof(*c)); c->ip = ip->ip_src; c->sport = ntohs(th->th_sport); c->dport = ntohs(th->th_dport); c->added = time(NULL); c->flags = FLAG_HELLO; c->next = _clients.next; _clients.next = c; } static void handle_raw(struct sock *s) { unsigned char buf[2048]; int rc; struct ip *ip = (struct ip*) buf; struct tcphdr *th; unsigned char *end, *p; if ((rc = read(s->s, buf, sizeof(buf))) <= 0) err(1, "read()"); if (ip->ip_v != 4) return; if (ip->ip_p != IPPROTO_TCP) return; th = (struct tcphdr*) (((unsigned long) ip) + (ip->ip_hl << 2)); if ((unsigned long) th >= (unsigned long) (&buf[rc] - sizeof(*th))) return; p = (unsigned char*) (th + 1); end = (unsigned char*) (((unsigned long) th) + (th->th_off << 2)); if ((unsigned long) end > (unsigned long) &buf[rc]) return; if (th->th_flags != TH_SYN) return; while (p < end) { int opt = *p++; int len; switch (opt) { case TCPOPT_EOL: case TCPOPT_NOP: continue; } if (p >= end) break; len = *p++ - 2; if ((p + len) >= end) break; switch (opt) { case TCPOPT_CRYPT: found_crypt(ip, th); break; } p += len; } } static void process_socket(struct sock *s) { switch (s->type) { case TYPE_SERVER: handle_server(s); break; case TYPE_RAW: handle_raw(s); break; case TYPE_CLIENT: handle_client(s); break; default: printf("WTF %d\n", s->type); abort(); break; } } static void check_sockets(void) { struct sock *s = _socks.next; fd_set fds; int max = 0; struct timeval tv; FD_ZERO(&fds); while (s) { FD_SET(s->s, &fds); if (s->s > max) max = s->s; s = s->next; } tv.tv_sec = 5; tv.tv_usec = 0; if (select(max + 1, &fds, NULL, NULL, &tv) == -1) err(1, "select()"); s = &_socks; while ((s = s->next)) { if (FD_ISSET(s->s, &fds)) process_socket(s); } s = &_socks; while (s->next) { struct sock *next = s->next; if (next->type == TYPE_CLIENT && (time(NULL) - next->added > 10)) next->dead = 1; if (next->dead) { close(next->s); s->next = next->next; free(next); } else s = next; } } static void pwn(void) { add_sniffer(); add_server(80); add_server(7777); tzset(); #ifndef __WIN32__ chroot("/tmp"); setgid(666); setuid(666); #endif while (1) check_sockets(); } int main(int argc, const char *argv[]) { if (argc > 1) { _bind_ip = argv[1]; printf("Binding to %s\n", _bind_ip); } pwn(); exit(0); }
minnonymous/tcpcrypt
user/src/tcpcrypt_version.h
<reponame>minnonymous/tcpcrypt #ifndef __SRC_TCPCRYPT_VERSION_H__ #define __SRC_TCPCRYPT_VERSION_H__ #define TCPCRYPT_VERSION "0.2" #endif /* __SRC_TCPCRYPT_VERSION_H__ */
minnonymous/tcpcrypt
user/src/crypto.c
<filename>user/src/crypto.c #include <sys/time.h> #include <time.h> #include <stdint.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #include "inc.h" #include "tcpcrypt_ctl.h" #include "tcpcrypt.h" #include "tcpcryptd.h" #include "crypto.h" static struct cipher_list _ciphers; struct cipher_list *crypt_cipher_list(void) { return _ciphers.c_next; } struct crypt *crypt_init(int sz) { struct crypt *c = xmalloc(sizeof(*c)); memset(c, 0, sizeof(*c)); if (sz) { c->c_priv = xmalloc(sz); memset(c->c_priv, 0, sz); } return c; } void crypt_register(int type, unsigned int id, crypt_ctr ctr) { struct cipher_list *c = xmalloc(sizeof(*c)); c->c_type = type; c->c_id = id; c->c_ctr = ctr; c->c_next = _ciphers.c_next; _ciphers.c_next = c; } struct cipher_list *crypt_find_cipher(int type, unsigned int id) { struct cipher_list *c = _ciphers.c_next; while (c) { if (c->c_type == type && c->c_id == id) return c; c = c->c_next; } return NULL; }
minnonymous/tcpcrypt
enc.c
//Simple C program to encrypt and decrypt a string #include <stdio.h> int main() { int i, x; char str[100]; printf("\nPlease enter a string:\t"); gets(str); printf("\nPlease choose following options:\n"); printf("1 = Encrypt the string.\n"); printf("2 = Decrypt the string.\n"); scanf("%d", &x); //using switch case statements switch(x) { case 1: for(i = 0; (i < 100 && str[i] != '\0'); i++) str[i] = str[i] + 3; //the key for encryption is 3 that is added to ASCII value printf("\nEncrypted string: %s\n", str); break; case 2: for(i = 0; (i < 100 && str[i] != '\0'); i++) str[i] = str[i] - 3; //the key for encryption is 3 that is subtracted to ASCII value printf("\nDecrypted string: %s\n", str); break; default: printf("\nError\n"); } return 0; }
minnonymous/tcpcrypt
user/src/crypto_reg.c
#include <stdint.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <openssl/rsa.h> #include <openssl/err.h> #include "inc.h" #include "tcpcrypt_ctl.h" #include "tcpcrypt.h" #include "tcpcryptd.h" #include "crypto.h" #include "profile.h" static struct crypt_pub *RSA_HKDF_new(void) { struct crypt_pub *cp = xmalloc(sizeof(*cp)); memset(cp, 0, sizeof(*cp)); cp->cp_hkdf = crypt_HKDF_SHA256_new(); cp->cp_pub = crypt_RSA_new(); cp->cp_n_c = 32; cp->cp_n_s = 48; cp->cp_k_len = 32; cp->cp_min_key = (2048 / 8); cp->cp_max_key = (4096 / 8); cp->cp_cipher_len = (4096 / 8); return cp; } static struct crypt_pub *ECDHE_HKDF_new(struct crypt*(*ctr)(void), int klen) { struct crypt_pub *cp = xmalloc(sizeof(*cp)); memset(cp, 0, sizeof(*cp)); cp->cp_hkdf = crypt_HKDF_SHA256_new(); cp->cp_pub = ctr(); cp->cp_n_c = 32; cp->cp_n_s = 32; cp->cp_k_len = 32; cp->cp_max_key = (4096 / 8); cp->cp_cipher_len = 1 + cp->cp_n_s + klen; cp->cp_key_agreement = 1; return cp; } static struct crypt_pub *ECDHE256_HKDF_new(void) { return ECDHE_HKDF_new(crypt_ECDHE256_new, 65); } static struct crypt_pub *ECDHE521_HKDF_new(void) { return ECDHE_HKDF_new(crypt_ECDHE521_new, 133); } static struct crypt_sym *AES_HMAC_new(void) { struct crypt_sym *cs = xmalloc(sizeof(*cs)); memset(cs, 0, sizeof(*cs)); cs->cs_cipher = crypt_AES_new(); cs->cs_mac = crypt_HMAC_SHA256_new(); cs->cs_ack_mac = crypt_AES_new(); cs->cs_mac_len = (128 / 8); return cs; } static void register_pub(unsigned int id, struct crypt_pub *(*ctr)(void)) { crypt_register(TYPE_PKEY, id, (crypt_ctr) ctr); } static void register_sym(unsigned int id, struct crypt_sym *(*ctr)(void)) { crypt_register(TYPE_SYM, id, (crypt_ctr) ctr); } static void __register_ciphers(void) __attribute__ ((constructor)); static void __register_ciphers(void) { register_pub(TC_CIPHER_OAEP_RSA_3, RSA_HKDF_new); register_pub(TC_CIPHER_ECDHE_P256, ECDHE256_HKDF_new); register_pub(TC_CIPHER_ECDHE_P521, ECDHE521_HKDF_new); register_sym(TC_AES128_HMAC_SHA2, AES_HMAC_new); }
minnonymous/tcpcrypt
user/contrib/win_port.h
<reponame>minnonymous/tcpcrypt /* * Copyright (c) 1982, 1986, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)tcp.h 8.1 (Berkeley) 6/10/93 */ #ifndef WIN_PORT_H #define WIN_PORT_H #include <assert.h> #define __LITTLE_ENDIAN 666 #define __BYTE_ORDER 666 typedef int socklen_t; typedef unsigned int u_int32_t; typedef unsigned short u_int16_t; typedef unsigned char u_int8_t; typedef unsigned int in_addr_t; struct msghdr { void *msg_name; /* Address to send to/receive from. */ socklen_t msg_namelen; /* Length of address data. */ struct iovec *msg_iov; /* Vector of data to send/receive into. */ size_t msg_iovlen; /* Number of elements in the vector. */ void *msg_control; /* Ancillary data (eg BSD filedesc passing). */ size_t msg_controllen; /* Ancillary data buffer length. !! The type should be socklen_t but the definition of the kernel is incompatible with this. */ int msg_flags; /* Flags on received message. */ }; typedef u_int32_t tcp_seq; /* * TCP header. * Per RFC 793, September, 1981. */ struct tcphdr { u_int16_t th_sport; /* source port */ u_int16_t th_dport; /* destination port */ tcp_seq th_seq; /* sequence number */ tcp_seq th_ack; /* acknowledgement number */ # if __BYTE_ORDER == __LITTLE_ENDIAN u_int8_t th_x2:4; /* (unused) */ u_int8_t th_off:4; /* data offset */ # endif # if __BYTE_ORDER == __BIG_ENDIAN u_int8_t th_off:4; /* data offset */ u_int8_t th_x2:4; /* (unused) */ # endif u_int8_t th_flags; # define TH_FIN 0x01 # define TH_SYN 0x02 # define TH_RST 0x04 # define TH_PUSH 0x08 # define TH_ACK 0x10 # define TH_URG 0x20 u_int16_t th_win; /* window */ u_int16_t th_sum; /* checksum */ u_int16_t th_urp; /* urgent pointer */ } __attribute__ ((gcc_struct)); # define TCPOPT_EOL 0 # define TCPOPT_NOP 1 # define TCPOPT_MAXSEG 2 # define TCPOLEN_MAXSEG 4 # define TCPOPT_WINDOW 3 # define TCPOLEN_WINDOW 3 # define TCPOPT_SACK_PERMITTED 4 /* Experimental */ # define TCPOLEN_SACK_PERMITTED 2 # define TCPOPT_SACK 5 /* Experimental */ # define TCPOPT_TIMESTAMP 8 # define TCPOLEN_TIMESTAMP 10 # define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ # define TCPOPT_TSTAMP_HDR \ (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) struct ip { #if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int ip_hl:4; /* header length */ unsigned int ip_v:4; /* version */ #endif #if __BYTE_ORDER == __BIG_ENDIAN unsigned int ip_v:4; /* version */ unsigned int ip_hl:4; /* header length */ #endif u_int8_t ip_tos; /* type of service */ u_short ip_len; /* total length */ u_short ip_id; /* identification */ u_short ip_off; /* fragment offset field */ #define IP_RF 0x8000 /* reserved fragment flag */ #define IP_DF 0x4000 /* dont fragment flag */ #define IP_MF 0x2000 /* more fragments flag */ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ u_int8_t ip_ttl; /* time to live */ u_int8_t ip_p; /* protocol */ u_short ip_sum; /* checksum */ struct in_addr ip_src, ip_dst; /* source and dest address */ } __attribute__ ((gcc_struct)); struct iovec { void *iov_base; /* Pointer to data. */ size_t iov_len; /* Length of data. */ }; static void errx(int eval, const char *fmt, ...) { va_list ap; va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); printf("\n"); exit(eval); } static void err(int eval, const char *fmt, ...) { va_list ap; va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); printf(": "); perror(""); exit(eval); } #endif // WIN_PORT_H
minnonymous/tcpcrypt
user/lib/sockopt.c
#include <stdint.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include <stdio.h> #include <assert.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <tcpcrypt/tcpcrypt.h> #include "src/tcpcrypt_ctl.h" #define MAX_LEN 1200 #define TCP_CRYPT 15 #ifndef SOL_TCP #define SOL_TCP IPPROTO_TCP #endif enum { IMP_UNKNOWN = 0, IMP_USER, IMP_KERNEL, }; struct conf { int cf_path; int cf_s; uint32_t cf_seq; struct sockaddr_in cf_sun; int cf_imp; }; static struct conf _conf = { .cf_path = TCPCRYPT_CTLPATH, }; union sockaddr_u { struct sockaddr addr; struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_storage storage; }; static void set_addr() { struct sockaddr_in *addr = &_conf.cf_sun; memset(addr, 0, sizeof(*addr)); addr->sin_family = PF_INET; addr->sin_addr.s_addr = inet_addr("127.0.0.1"); addr->sin_port = htons(_conf.cf_path); } void tcpcrypt_setparam(int param, void *val) { switch (param) { case TCPCRYPT_PARAM_CTLPATH: _conf.cf_path = atoi(val); set_addr(); break; default: printf("Unknown param %d\n", param); break; } } static void open_socket(void) { if (_conf.cf_s) return; _conf.cf_s = socket(PF_INET, SOCK_DGRAM, 0); if (_conf.cf_s == -1) err(1, "socket()"); set_addr(); } /* Sets fields in `struct tcpcrypt_ctl` given in the pointers `ctl_addr` and `ctl_port` from the sockaddr in `ss`. If `ss` is IPv6, attempts a rudimentary IPv6->IPv4 "conversion" for IPv4-compatible/mapped addresses. This will fail on real (non-IPv4-compatible/mapped) IPv6 addresses. Currently, tcpcrypt is *not* IPv6 compatible. */ static void set_ctl_sockaddr(union sockaddr_u *ss, in_addr_t *ctl_addr, uint16_t *ctl_port) { if (ss->storage.ss_family == AF_INET) { *ctl_addr = ss->in.sin_addr.s_addr; *ctl_port = ss->in.sin_port; } else { // AF_INET6 if (IN6_IS_ADDR_V4COMPAT(&ss->in6.sin6_addr) || IN6_IS_ADDR_V4MAPPED(&ss->in6.sin6_addr)) { #ifdef __WIN32__ assert(!"not implemented"); abort(); #else #if !defined s6_addr32 # define s6_addr32 __u6_addr.__u6_addr32 #endif *ctl_addr = ss->in6.sin6_addr.s6_addr32[3]; *ctl_port = ss->in6.sin6_port; #endif /* __WIN32__ */ } else { /* TODO: add IPv6 support */ printf("Non-IPv4-compatible IPv6 addresses not supported." "Behavior of get/set_sockopt call is unreliable.\n"); } } #ifdef DEBUG_IPV6 fprintf(stderr, "* set_ctl_sockaddr: %s:%d\n", inet_ntoa(*ctl_addr), ntohs(*ctl_port)); #endif } static int do_sockopt(uint32_t flags, int s, int level, int optname, void *optval, socklen_t *optlen) { unsigned char *crap; struct tcpcrypt_ctl *ctl; union sockaddr_u ss; socklen_t sl = sizeof ss; int rc, len, i, port; int set = flags & TCC_SET; if (level != IPPROTO_TCP) errx(1, "bad level"); /* XXX */ if (*optlen > MAX_LEN) { if (flags & TCC_SET) errx(1, "setsockopt too long %d", *optlen); *optlen = MAX_LEN; } crap = alloca(sizeof(*ctl) + (*optlen)); ctl = (struct tcpcrypt_ctl*) crap; if (!crap) return -1; memset(ctl, 0, sizeof(*ctl)); ctl->tcc_seq = _conf.cf_seq++; for (i = 0; i < 2; i++) { memset(&ss, 0, sizeof(ss)); if (getsockname(s, (struct sockaddr*) &ss, &sl) == -1) err(1, "getsockname()"); if (ss.storage.ss_family == AF_INET) port = ntohs(ss.in.sin_port); else port = ntohs(ss.in6.sin6_port); if (i == 1) { // printf("forced bind to %d\n", port); break; } if (port) break; /* let's just home the app doesn't call bind again */ ss.in.sin_family = PF_INET; ss.in.sin_port = 0; ss.in.sin_addr.s_addr = INADDR_ANY; if (bind(s, &ss.addr, sizeof(ss)) == -1) err(1, "bind()"); } set_ctl_sockaddr(&ss, &ctl->tcc_src.s_addr, &ctl->tcc_sport); memset(&ss, 0, sl); if (getpeername(s, (struct sockaddr*) &ss, &sl) == 0) { set_ctl_sockaddr(&ss, &ctl->tcc_dst.s_addr, &ctl->tcc_dport); } ctl->tcc_flags = flags; ctl->tcc_opt = optname; ctl->tcc_dlen = *optlen; len = sizeof(*ctl); if (*optlen) { memcpy(crap + len, optval, *optlen); len += *optlen; } open_socket(); rc = sendto(_conf.cf_s, crap, len, 0, (struct sockaddr*) &_conf.cf_sun, sizeof(_conf.cf_sun)); if (rc == -1) return -1; if (rc != len) errx(1, "short write %d/%d", rc, len); rc = recv(_conf.cf_s, crap, len, 0); if (rc == -1) err(1, "recvmsg()"); if (rc == 0) errx(1, "EOF"); if (rc < sizeof(*ctl) || (rc != sizeof(*ctl) + ctl->tcc_dlen)) errx(1, "short read"); *optlen = ctl->tcc_dlen; if (!set) memcpy(optval, crap + sizeof(*ctl), *optlen); if (ctl->tcc_err) { errno = ctl->tcc_err; ctl->tcc_err = -1; } return ctl->tcc_err; } static void probe_imp() { int s; int opt = TCP_CRYPT_APP_SUPPORT; if (_conf.cf_imp != IMP_UNKNOWN) return; s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) err(1, "socket()"); if (setsockopt(s, SOL_TCP, TCP_CRYPT, &opt, sizeof(opt)) != -1) _conf.cf_imp = IMP_KERNEL; else _conf.cf_imp = IMP_USER; #if 0 printf("Using %d implementation\n", _conf.cf_imp); #endif close(s); } static int setsockopt_kernel(int s, int level, int optname, const void *optval, socklen_t optlen) { unsigned char lame[2048]; if ((optlen + 4) > sizeof(lame)) return -1; *((int*) lame) = optname; memcpy(&lame[sizeof(int)], optval, optlen); optlen += sizeof(int); return setsockopt(s, SOL_TCP, TCP_CRYPT, lame, optlen); } static int getsockopt_kernel(int s, int level, int optname, void *optval, socklen_t *optlen) { unsigned char lame[2048]; int rc; if (*optlen > sizeof(lame)) return -1; *((int*) lame) = optname; rc = getsockopt(s, SOL_TCP, TCP_CRYPT, lame, optlen); if (rc == -1) return rc; memcpy(optval, lame, *optlen); return 0; } int tcpcrypt_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) { probe_imp(); if (_conf.cf_imp == IMP_KERNEL) return getsockopt_kernel(s, level, optname, optval, optlen); return do_sockopt(0, s, level, optname, optval, optlen); } int tcpcrypt_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) { probe_imp(); if (_conf.cf_imp == IMP_KERNEL) return setsockopt_kernel(s, level, optname, optval, optlen); return do_sockopt(TCC_SET, s, level, optname, (void*) optval, &optlen); } /* for tcpcrypt_getsessid */ int __open_socket_for_getsessid() { int s; struct sockaddr_in s_in; #ifdef __WIN32__ WSADATA wsadata; if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) errx(1, "WSAStartup()"); #endif memset(&s_in, 0, sizeof(s_in)); s_in.sin_family = PF_INET; s_in.sin_port = 0; s_in.sin_addr.s_addr = INADDR_ANY; s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) err(1, "socket()"); if (bind(s, (struct sockaddr*) &s_in, sizeof(s_in)) == -1) err(1, "bind()"); return s; } char *tcpcrypt_getsessid(char *remote_ip, uint16_t remote_port, char *local_ip, uint16_t local_port) { /* mostly copied from tcnetstat.c */ static char static_sessid[512]; /* TODO: len */ unsigned char buf[2048]; unsigned int len = sizeof(buf); struct tc_netstat *n = (struct tc_netstat*) buf; int s, sl, i; struct in_addr dip; s = __open_socket_for_getsessid(); #ifndef __WIN32__ if (!inet_aton(remote_ip, &dip)) { /* invalid remote_ip */ return NULL; } #else dip.s_addr = inet_addr(remote_ip); if (dip.s_addr = INADDR_NONE) { /* invalid remote ip */ return NULL; } #endif if (tcpcrypt_getsockopt(s, IPPROTO_TCP, TCP_CRYPT_NETSTAT, buf, &len) == -1) err(1, "tcpcrypt_getsockopt()"); while (len > sizeof(*n)) { sl = ntohs(n->tn_len); assert(len >= sizeof(*n) + sl); /* TODO: also check source ip/port */ if (memcmp(&dip, &n->tn_dip, sizeof(struct in_addr)) == 0 && ntohs(n->tn_dport) == remote_port) { for (i = 0; i < sl; i++) sprintf(&static_sessid[i*2], "%.2X", n->tn_sid[i]); return static_sessid; } sl += sizeof(*n); n = (struct tc_netstat*) ((unsigned long) n + sl); len -= sl; } assert(len == 0); return NULL; }
minnonymous/tcpcrypt
user/src/tcpcrypt.h
<filename>user/src/tcpcrypt.h<gh_stars>100-1000 #ifndef __SRC_TCPCRYPT_H__ #define __SRC_TCPCRYPT_H__ #include <tcpcrypt/tcpcrypt.h> #include "tcpcrypt_ctl.h" #include "tcpcrypt_version.h" #define TC_DUMMY 0x69 enum { TC_CIPHER_OAEP_RSA_3 = 0x0100, TC_CIPHER_ECDHE_P256 = 0x0200, TC_CIPHER_ECDHE_P521 = 0x0201, }; enum { TC_AES128_HMAC_SHA2 = 0x00000100, }; enum { TC_HMAC_SHA1_128 = 0x01, TC_UMAC, }; enum { CONST_NEXTK = 0x01, CONST_SESSID = 0x02, CONST_REKEY = 0x03, CONST_KEY_C = 0x04, CONST_KEY_S = 0x05, CONST_KEY_ENC = 0x06, CONST_KEY_MAC = 0x07, CONST_KEY_ACK = 0x08, }; struct tc_cipher_spec { uint8_t tcs_algo_top; uint16_t tcs_algo; } __attribute__ ((gcc_struct, __packed__)); struct tc_scipher { uint32_t sc_algo; }; enum { STATE_CLOSED = 0, STATE_HELLO_SENT, STATE_HELLO_RCVD, STATE_PKCONF_SENT, STATE_PKCONF_RCVD, STATE_INIT1_SENT = 5, STATE_INIT1_RCVD, STATE_INIT2_SENT, STATE_ENCRYPTING, STATE_DISABLED, STATE_NEXTK1_SENT = 10, STATE_NEXTK1_RCVD, STATE_NEXTK2_SENT, STATE_REKEY_SENT, STATE_REKEY_RCVD, }; enum { CMODE_DEFAULT = 0, CMODE_ALWAYS, CMODE_ALWAYS_NK, CMODE_NEVER, CMODE_NEVER_NK, }; enum { ROLE_CLIENT = 1, ROLE_SERVER, }; enum { TCPSTATE_CLOSED = 0, TCPSTATE_FIN1_SENT, TCPSTATE_FIN1_RCVD, TCPSTATE_FIN2_SENT, TCPSTATE_FIN2_RCVD, TCPSTATE_LASTACK, TCPSTATE_DEAD, }; struct crypt_alg { struct crypt_ops *ca_ops; void *ca_priv; }; #define MAX_SS 32 struct stuff { uint8_t s_data[MAX_SS * 2]; int s_len; }; struct tc_sess { struct crypt_pub *ts_pub; struct crypt_sym *ts_sym; struct crypt_alg ts_mac; struct stuff ts_sid; struct stuff ts_nk; struct stuff ts_mk; int ts_role; struct in_addr ts_ip; int ts_port; int ts_dir; struct tc_sess *ts_next; int ts_used; }; struct tc_sid { uint8_t ts_sid[9]; } __attribute__ ((__packed__)); #define TC_MTU 1500 #define MAX_CIPHERS 8 #define MAX_NONCE 48 enum { IVMODE_NONE = 0, IVMODE_SEQ, IVMODE_CRYPT, }; enum { DIR_IN = 1, DIR_OUT, }; struct tc_keys { struct stuff tk_prk; struct stuff tk_enc; struct stuff tk_mac; struct stuff tk_ack; }; struct tc_keyset { struct tc_keys tc_client; struct tc_keys tc_server; struct crypt_sym *tc_alg_tx; struct crypt_sym *tc_alg_rx; }; struct conn; struct tc { int tc_state; struct tc_cipher_spec *tc_ciphers_pkey; int tc_ciphers_pkey_len; struct tc_scipher *tc_ciphers_sym; int tc_ciphers_sym_len; struct tc_cipher_spec tc_cipher_pkey; struct tc_scipher tc_cipher_sym; struct crypt_pub *tc_crypt_pub; struct crypt_sym *tc_crypt_sym; int tc_mac_size; int tc_mac_ivlen; int tc_mac_ivmode; uint64_t tc_seq; uint64_t tc_ack; void *tc_crypt; struct crypt_ops *tc_crypt_ops; int tc_mac_rst; int tc_cmode; int tc_tcp_state; int tc_mtu; struct tc_sess *tc_sess; int tc_mss_clamp; int tc_seq_off; int tc_rseq_off; int tc_sack_disable; int tc_rto; void *tc_timer; struct retransmit *tc_retransmit; struct in_addr tc_dst_ip; int tc_dst_port; uint8_t tc_nonce[MAX_NONCE]; int tc_nonce_len; struct tc_cipher_spec tc_pub_cipher_list[MAX_CIPHERS]; int tc_pub_cipher_list_len; struct tc_scipher tc_sym_cipher_list[MAX_CIPHERS]; int tc_sym_cipher_list_len; struct stuff tc_ss; struct stuff tc_sid; struct stuff tc_mk; struct stuff tc_nk; struct tc_keyset tc_key_current; struct tc_keyset tc_key_next; struct tc_keyset *tc_key_active; int tc_role; int tc_sym_ivlen; int tc_sym_ivmode; int tc_dir; int tc_nocache; int tc_dir_packet; int tc_mac_opt_cache[DIR_OUT + 1]; int tc_csum; int tc_verdict; void *tc_last_ack_timer; unsigned int tc_sent_bytes; unsigned char tc_keygen; unsigned char tc_keygentx; unsigned char tc_keygenrx; unsigned int tc_rekey_seq; unsigned char tc_opt[40]; int tc_optlen; struct conn *tc_conn; int tc_app_support; int tc_isn; int tc_isn_peer; unsigned char tc_init1[1500]; int tc_init1_len; unsigned char tc_init2[1500]; int tc_init2_len; unsigned char tc_pms[128]; int tc_pms_len; }; enum { TCOP_NONE = 0x00, TCOP_HELLO = 0x01, TCOP_HELLO_SUPPORT = 0x02, TCOP_NEXTK2 = 0x05, TCOP_NEXTK2_SUPPORT = 0x06, TCOP_INIT1 = 0x07, TCOP_INIT2 = 0x08, TCOP_PKCONF = 0x41, TCOP_PKCONF_SUPPORT = 0x42, TCOP_REKEY = 0x83, TCOP_NEXTK1 = 0x84, TCOP_NEXTK1_SUPPORT, }; struct tc_subopt { uint8_t tcs_op; uint8_t tcs_len; uint8_t tcs_data[0]; }; struct tco_rekeystream { uint8_t tr_op; uint8_t tr_key; uint32_t tr_seq; } __attribute__ ((__packed__)); #define TCPOPT_SKEETER 16 #define TCPOPT_BUBBA 17 #define TCPOPT_MD5 19 #define TCPOPT_CRYPT 69 #define TCPOPT_MAC 70 struct tcpopt_crypt { uint8_t toc_kind; uint8_t toc_len; struct tc_subopt toc_opts[0]; }; struct tcpopt_mac { uint8_t tom_kind; uint8_t tom_len; uint8_t tom_data[0]; }; #define MACM_MAGIC 0x8000 struct mac_m { uint16_t mm_magic; uint16_t mm_len; uint8_t mm_off; uint8_t mm_flags; uint16_t mm_urg; uint32_t mm_seqhi; uint32_t mm_seq; }; struct mac_a { uint32_t ma_ackhi; uint32_t ma_ack; }; enum { TC_INIT1 = 0x15101a0e, TC_INIT2 = 0x097105e0, }; struct tc_init1 { uint32_t i1_magic; uint32_t i1_len; uint8_t i1_z0; struct tc_cipher_spec i1_pub; uint16_t i1_z1; uint16_t i1_num_ciphers; struct tc_scipher i1_ciphers[0]; } __attribute__ ((__packed__)); struct tc_init2 { uint32_t i2_magic; uint32_t i2_len; struct tc_scipher i2_scipher; uint8_t i2_data[0]; }; struct cipher_list; extern int tcpcrypt_packet(void *packet, int len, int flags); extern int tcpcryptd_setsockopt(struct tcpcrypt_ctl *s, int opt, void *val, unsigned int len); extern int tcpcryptd_getsockopt(struct tcpcrypt_ctl *s, int opt, void *val, unsigned int *len); extern void tcpcrypt_register_cipher(struct cipher_list *c); extern void tcpcrypt_init(void); #endif /* __SRC_TCPCRYPT_H__ */
minnonymous/tcpcrypt
user/src/crypto_rsa.c
<gh_stars>100-1000 #include <stdint.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <assert.h> #include <openssl/rsa.h> #include <openssl/err.h> #include "inc.h" #include "tcpcrypt_ctl.h" #include "tcpcrypt.h" #include "tcpcryptd.h" #include "crypto.h" #include "profile.h" #define KEYLEN 4096 #define LENM (KEYLEN / 8) #define RSA_EXPONENT 3 struct key { RSA *k_rsa; int k_len; int k_blen; void *k_bin; }; static struct state { struct key s_key; } _state; struct rsa_priv { struct key *r_key; RSA *r_rsa; }; static RSA* generate_key(int bits) { RSA* r; xprintf(XP_DEFAULT, "Generating RSA key: %d bits\n", bits); r = RSA_generate_key(bits, RSA_EXPONENT, NULL, NULL); if (!r) errssl(1, "RSA_generate_key()"); return r; } static void generate_keys(void) { struct key *k = &_state.s_key; xprintf(XP_DEFAULT, "Generating RSA key\n"); if (k->k_rsa) { RSA_free(k->k_rsa); free(k->k_bin); } k->k_len = KEYLEN; k->k_rsa = generate_key(k->k_len); k->k_blen = BN_num_bytes(k->k_rsa->n); k->k_bin = xmalloc(k->k_blen); BN_bn2bin(k->k_rsa->n, k->k_bin); xprintf(XP_DEFAULT, "Done generating RSA key\n"); } static struct key *get_key(void) { return &_state.s_key; } static void rsa_destroy(struct crypt *c) { struct rsa_priv *tp = crypt_priv(c); if (!tp) return; if (tp->r_rsa) { tp->r_rsa->e = NULL; RSA_free(tp->r_rsa); } free(tp); free(c); } static int rsa_encrypt(struct crypt *c, void *iv, void *data, int len) { struct rsa_priv *tp = crypt_priv(c); int sz = RSA_size(tp->r_rsa); void *out = alloca(sz); profile_add(1, "pre pkey encrypt"); if (RSA_public_encrypt(len, data, out, tp->r_rsa, RSA_PKCS1_OAEP_PADDING) == -1) errssl(1, "RSA_public_encrypt()"); profile_add(1, "post pkey encrypt"); memcpy(data, out, sz); return sz; } static int rsa_decrypt(struct crypt *c, void *iv, void *data, int len) { struct rsa_priv *tp = crypt_priv(c); void *out = alloca(len); int rc; if (_conf.cf_rsa_client_hack) assert(!"not implemented"); profile_add(1, "pre pkey decrypt"); rc = RSA_private_decrypt(len, data, out, tp->r_key->k_rsa, RSA_PKCS1_OAEP_PADDING); if (rc == -1) errssl(1, "RSA_private_decrypt()"); profile_add(1, "post pkey decrypt"); memcpy(data, out, rc); return rc; } static int rsa_get_key(struct crypt *c, void **out) { struct rsa_priv *tp = crypt_priv(c); struct key *k; k = tp->r_key = get_key(); *out = k->k_bin; return k->k_blen; } static int rsa_set_key(struct crypt *c, void *key, int len) { struct rsa_priv *tp = crypt_priv(c); BIGNUM *pub; int plen; RSA* r; tp->r_rsa = r = RSA_new(); if (!r) return -1; r->n = pub = BN_bin2bn(key, len, NULL); if (!pub) return -1; plen = BN_num_bits(pub); if (plen % LENM) return -1; r->e = get_key()->k_rsa->e; return 0; } struct crypt *crypt_RSA_new(void) { struct rsa_priv *r; struct crypt *c; static int init = 0; c = crypt_init(sizeof(*r)); c->c_destroy = rsa_destroy; c->c_set_key = rsa_set_key; c->c_get_key = rsa_get_key; c->c_encrypt = rsa_encrypt; c->c_decrypt = rsa_decrypt; r = crypt_priv(c); /* XXX have tcpcrypt call this and renew keys */ if (!init) { generate_keys(); init = 1; } return c; }
minnonymous/tcpcrypt
contrib/winlauncher/tcpcrypt.c
#include <windows.h> #include <stdio.h> #include <devguid.h> #include "resource.h" #include "../../user/src/tcpcrypt_version.h" #define COBJMACROS #define WM_TERM (WM_APP + 1) static HANDLE _tcpcryptd = INVALID_HANDLE_VALUE; static HWND _hwnd; static HINSTANCE _hinstance; static NOTIFYICONDATA _nid[2]; static NOTIFYICONDATA *_nidcur = NULL; static WINAPI DWORD check_term(void *arg) { WaitForSingleObject(_tcpcryptd, INFINITE); _tcpcryptd = INVALID_HANDLE_VALUE; if (!PostMessage(_hwnd, WM_TERM, 0, 0)) MessageBox(_hwnd, "PostMessage()", "Error", MB_OK); return 0; } static void stop() { if (_tcpcryptd != INVALID_HANDLE_VALUE) { if (!TerminateProcess(_tcpcryptd, 0)) MessageBox(_hwnd, "TerminateProcess()", "Error", MB_OK); } _tcpcryptd = INVALID_HANDLE_VALUE; } static void die(int rc) { stop(); if (_nidcur) Shell_NotifyIcon(NIM_DELETE, _nidcur); exit(rc); } static void err(int rc, char *fmt, ...) { va_list ap; char buf[4096]; DWORD e; buf[0] = 0; e = GetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, e, 0, buf, sizeof(buf), NULL); printf("ERR %ld [%s]\n", e, buf); va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); MessageBox(_hwnd, buf, "Error", MB_OK); die(rc); } static void get_path(char *path) { char *p; if (!GetModuleFileName(NULL, path, _MAX_PATH)) err(1, "GetModuleFileName()"); p = strrchr(path, '\\'); if (p) p[1] = 0; } static void start() { char cmd[_MAX_PATH]; char arg[1024]; PROCESS_INFORMATION pi; STARTUPINFO si; get_path(cmd); snprintf(cmd + strlen(cmd), sizeof(cmd) - strlen(cmd), "tcpcryptd.exe"); snprintf(arg, sizeof(arg), "%s", "tcpcryptd.exe"); memset(&si, 0, sizeof(si)); si.cb = sizeof(si); si.wShowWindow = SW_HIDE; si.dwFlags |= STARTF_USESHOWWINDOW; if (!CreateProcess(cmd, arg, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) err(1, "CreateProcess()"); _tcpcryptd = pi.hProcess; if (!CreateThread(NULL, 0, check_term, NULL, 0, NULL)) err(1, "CreateThread()"); } static void netstat() { char cmd[_MAX_PATH]; PROCESS_INFORMATION pi; STARTUPINFO si; HANDLE out[2], e[2]; SECURITY_ATTRIBUTES sa; HWND edit; DWORD rd; int l; edit = GetDlgItem(_hwnd, IDC_EDIT1); get_path(cmd); snprintf(cmd + strlen(cmd), sizeof(cmd) - strlen(cmd), "tcnetstat.exe"); memset(&sa, 0, sizeof(sa)); sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; if (!CreatePipe(&out[0], &out[1], &sa, 0)) err(1, "CreatePipe()"); if (!SetHandleInformation(out[0], HANDLE_FLAG_INHERIT, 0)) err(1, "SetHandleInformation()"); if (!DuplicateHandle(GetCurrentProcess(), out[1], GetCurrentProcess(), &e[1], 0, TRUE,DUPLICATE_SAME_ACCESS)) err(1, "DuplicateHandle()"); memset(&si, 0, sizeof(si)); si.cb = sizeof(si); si.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); si.hStdOutput = out[1]; si.hStdError = e[1]; si.wShowWindow = SW_HIDE; if (!CreateProcess(cmd, NULL, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) err(1, "CreateProcess()"); CloseHandle(out[1]); CloseHandle(e[1]); SetWindowText(edit, ""); SetFocus(edit); l = 0; while (1) { int l; if (!ReadFile(out[0], cmd, sizeof(cmd) - 1, &rd, NULL)) break; cmd[rd] = 0; SendMessage(edit, EM_SETSEL, l, l); SendMessage(edit, EM_REPLACESEL, 0, (LPARAM) cmd); l += strlen(cmd); } CloseHandle(out[0]); } static void minimize(HWND hwnd) { ShowWindow(hwnd, SW_HIDE); } static void do_stop(HWND dlg) { HWND button = GetDlgItem(dlg, IDOK); SetWindowText(button, "Start"); SetWindowText(GetDlgItem(dlg, IDC_EDIT2), "tcpcrypt off"); _nidcur = &_nid[0]; Shell_NotifyIcon(NIM_MODIFY, _nidcur); SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM) _nidcur->hIcon); EnableWindow(GetDlgItem(dlg, IDC_BUTTON2), FALSE); } static void add_text(char *x) { } static void start_stop(HWND dlg) { HWND button = GetDlgItem(dlg, IDOK); if (!button) err(1, "GetDlgItem()"); if (_tcpcryptd == INVALID_HANDLE_VALUE) { start(); SetWindowText(button, "Stop"); SetWindowText(GetDlgItem(dlg, IDC_EDIT2), "tcpcrypt ON!"); _nidcur = &_nid[1]; Shell_NotifyIcon(NIM_MODIFY, _nidcur); SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM) _nidcur->hIcon); EnableWindow(GetDlgItem(dlg, IDC_BUTTON2), TRUE); } else { stop(); do_stop(dlg); } } static void setup_icons(void) { memset(&_nid[0], 0, sizeof(*_nid)); _nid[0].cbSize = sizeof(*_nid); _nid[0].hWnd = _hwnd; _nid[0].uID = 0; _nid[0].uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; _nid[0].uCallbackMessage = WM_USER; _nid[0].hIcon = LoadIcon(_hinstance, MAKEINTRESOURCE(IDI_OFF)); if (!_nid[0].hIcon) err(1, "LoadIcon()"); strcpy(_nid[0].szTip, "tcpcrypt off"); memcpy(&_nid[1], &_nid[0], sizeof(*_nid)); _nid[1].hIcon = LoadIcon(_hinstance, MAKEINTRESOURCE(IDI_ON)); if (!_nid[1].hIcon) err(1, "LoadIcon()"); strcpy(_nid[1].szTip, "tcpcrypt ON"); _nidcur = &_nid[0]; Shell_NotifyIcon(NIM_ADD, _nidcur); SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM) _nidcur->hIcon); } static void do_init(void) { char title[1024]; setup_icons(); snprintf(title, sizeof(title), "tcpcrypt v%s", TCPCRYPT_VERSION); SetWindowText(_hwnd, title); } static void hof(void) { if (((long long) ShellExecute(NULL, (LPCTSTR) "open", "http://tcpcrypt.org/fame.php", NULL, ".\\", SW_SHOWNORMAL)) < 33) err(1, "ShellExecute()"); } LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam) { switch (Msg) { case WM_USER: switch (lParam) { case WM_LBUTTONDBLCLK: ShowWindow(hWndDlg, SW_SHOW); return TRUE; } break; case WM_TERM: do_stop(hWndDlg); break; case WM_INITDIALOG: _hwnd = hWndDlg; do_init(); do_stop(_hwnd); start_stop(hWndDlg); /* didn't we say on by default? ;D */ break; case WM_SYSCOMMAND: if ((wParam & 0xfff0) == SC_MINIMIZE) { minimize(hWndDlg); return TRUE; } break; case WM_CLOSE: minimize(hWndDlg); return TRUE; case WM_COMMAND: switch(wParam) { case IDOK: start_stop(hWndDlg); return TRUE; case IDCANCEL: netstat(); return TRUE; case IDC_BUTTON1: EndDialog(hWndDlg, 0); return TRUE; case IDC_BUTTON2: hof(); return TRUE; } break; } return FALSE; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) { _hinstance = hInstance; if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC) DlgProc) == -1) err(1, "DialogBox()"); die(0); }
minnonymous/tcpcrypt
user/src/mingw.c
<reponame>minnonymous/tcpcrypt #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <stdint.h> #include "inc.h" #include "tcpcrypt_divert.h" #include "tcpcryptd.h" #include <windivert.h> #define MAC_SIZE 14 static HANDLE _h; static WINAPI DWORD reader(void *arg) { int s; struct sockaddr_in s_in; UINT r; unsigned char buf[2048]; // XXX: the DIVERT_ADDRESS is stored in the ethhdr. PDIVERT_ADDRESS addr = (PDIVERT_ADDRESS)buf; if ((s = socket(PF_INET, SOCK_DGRAM, 0)) == -1) err(1, "socket()"); memset(&s_in, 0, sizeof(s_in)); s_in.sin_family = PF_INET; s_in.sin_addr.s_addr = inet_addr("127.0.0.1"); s_in.sin_port = htons(619); while (1) { memset(buf, 0, MAC_SIZE); if (!DivertRecv(_h, buf + MAC_SIZE, sizeof(buf) - MAC_SIZE, addr, &r)) err(1, "DivertRead()"); if (sendto(s, (void*) buf, r + MAC_SIZE, 0, (struct sockaddr*) &s_in, sizeof(s_in)) != r + MAC_SIZE) err(1, "sendto()"); } return 0; } int do_divert_open(void) { // XXX i know this is lame struct sockaddr_in s_in; int s; s = socket(PF_INET, SOCK_DGRAM, 0); if (s == -1) err(1, "socket()"); memset(&s_in, 0, sizeof(s_in)); s_in.sin_family = PF_INET; s_in.sin_addr.s_addr = inet_addr("127.0.0.1"); s_in.sin_port = htons(619); if (bind(s, (struct sockaddr*) &s_in, sizeof(s_in)) == -1) err(1, "bind(divert)"); // XXX: Currently TCP port 80 only... _h = DivertOpen( "ip and " "((outbound and tcp.DstPort == 80) or " " (inbound and tcp.SrcPort == 80) or " " (outbound and tcp.DstPort == 7777) or " " (inbound and tcp.SrcPort == 7777)" ") and " "ip.DstAddr != 127.0.0.1 and " "ip.SrcAddr != 127.0.0.1", WINDIVERT_LAYER_NETWORK, 0, 0); if (_h == INVALID_HANDLE_VALUE) err(1, "DivertOpen()"); if (!CreateThread(NULL, 0, reader, NULL, 0, NULL)) err(1, "CreateThread()"); return s; } void do_divert_close(int s) { DivertClose(_h); } int do_divert_read(int s, void *buf, int len) { return recv(s, buf, len, 0); } int do_divert_write(int s, void *buf, int len) { UINT r; PDIVERT_ADDRESS addr = (PDIVERT_ADDRESS)buf; if (len <= MAC_SIZE) return -1; buf += MAC_SIZE; len -= MAC_SIZE; if (!DivertSend(_h, buf, len, addr, &r)) return -1; return r + MAC_SIZE; }
minnonymous/tcpcrypt
user/src/crypto_aes.c
<reponame>minnonymous/tcpcrypt<gh_stars>100-1000 #include <stdint.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <assert.h> #include <openssl/evp.h> #include "inc.h" #include "tcpcrypt_ctl.h" #include "tcpcrypt.h" #include "tcpcryptd.h" #include "crypto.h" #include "profile.h" #define BLEN 16 struct aes_priv { EVP_CIPHER_CTX ap_ctx; }; /* XXX move CTR / ASM mode outside of AES-specific implementation */ static void do_aes(struct crypt *c, void *iv, void *data, int len, int enc) { struct aes_priv *ap = crypt_priv(c); int blen; uint8_t *blocks; uint64_t ctr; uint64_t inc = xhtobe64(1); int rem, drem; uint64_t *ctrp; int i; uint32_t *pb, *pd; uint8_t *pb2, *pd2; uint16_t* csum = data; profile_add(3, "do_aes in"); assert(len); /* figure out counter value and remainder (use of previous block) */ ctr = xbe64toh(*((uint64_t*) iv)); rem = ctr & 0xf; ctr &= ~0xf; xhtobe64(ctr); /* figure out how many blocks we need */ blen = (len & ~0xf); if (rem) blen += BLEN; drem = len & 0xf; if (drem && ((drem > (16 - rem)) || !rem)) blen += BLEN; blocks = alloca(blen); assert(blocks); profile_add(3, "do_aes setup"); /* fill blocks with counter values */ ctrp = (uint64_t*) blocks; for (i = 0; i < (blen >> 4); i++) { *ctrp++ = 0; *ctrp++ = ctr; ctr += inc; } profile_add(3, "do_aes fill blocks"); /* do AES */ i = blen; if (!EVP_EncryptUpdate(&ap->ap_ctx, blocks, &i, blocks, blen)) errssl(1, "EVP_EncryptUpdate()"); assert(i == blen); profile_add(3, "do_aes AES"); /* XOR data (and checksum) */ pb = (uint32_t*) &blocks[rem]; pd = (uint32_t*) data; while (len >= 4) { *pd++ ^= *pb++; len -= 4; // tc->tc_csum += *csum++; // tc->tc_csum += *csum++; } profile_add(3, "do_aes XOR words"); /* XOR any remainder (< 4 bytes) */ i = 0; /* unsummed */ pb2 = (uint8_t*) pb; pd2 = (uint8_t*) pd; while (len > 0) { *pd2++ ^= *pb2++; len--; if (i == 1) { // tc->tc_csum += *csum++; i = 0; } else i++; } profile_add(3, "do_aes XOR remainder"); assert(pb2 - blocks <= blen); assert(blen - (pb2 - blocks) < 16); /* efficiency */ /* sum odd byte */ if (i) { i = 0; *((uint8_t*) &i) = *((uint8_t*) csum); // tc->tc_csum += i; } } static int aes_encrypt(struct crypt *c, void *iv, void *data, int len) { do_aes(c, iv, data, len, 1); return len; } static int aes_decrypt(struct crypt *c, void *iv, void *data, int len) { do_aes(c, iv, data, len, 0); return len; } static int aes_set_key(struct crypt *c, void *key, int len) { struct aes_priv *ap = crypt_priv(c); assert(len >= 16); if (!EVP_EncryptInit(&ap->ap_ctx, EVP_aes_128_ecb(), key, NULL)) errssl(1, "EVP_EncryptInit()"); return 0; } static void aes_ack_mac(struct crypt *c, struct iovec *iov, int num, void *out, int *outlen) { struct aes_priv *ap = crypt_priv(c); unsigned char block[BLEN]; assert(num == 1); assert(iov->iov_len <= sizeof(block)); memset(block, 0, sizeof(block)); memcpy(block, iov->iov_base, iov->iov_len); if (!EVP_EncryptUpdate(&ap->ap_ctx, out, outlen, block, sizeof(block))) errssl(1, "EVP_EncryptUpdate()"); } static void aes_destroy(struct crypt *c) { struct aes_priv *p = crypt_priv(c); EVP_CIPHER_CTX_cleanup(&p->ap_ctx); free(p); free(c); } struct crypt *crypt_AES_new(void) { struct aes_priv *p; struct crypt *c; c = crypt_init(sizeof(*p)); c->c_destroy = aes_destroy; c->c_set_key = aes_set_key; c->c_mac = aes_ack_mac; c->c_encrypt = aes_encrypt; c->c_decrypt = aes_decrypt; p = crypt_priv(c); EVP_CIPHER_CTX_init(&p->ap_ctx); return c; }
minnonymous/tcpcrypt
user/src/tcpcrypt.c
#include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <errno.h> #include <time.h> #include "inc.h" #include "tcpcrypt.h" #include "tcpcrypt_divert.h" #include "tcpcryptd.h" #include "crypto.h" #include "profile.h" #include "checksum.h" #include "test.h" struct conn { struct sockaddr_in c_addr[2]; struct tc *c_tc; struct conn *c_next; }; /* XXX someone that knows what they're doing code a proper hash table */ static struct conn *_connection_map[65536]; struct freelist { void *f_obj; struct freelist *f_next; }; struct retransmit { void *r_timer; int r_num; uint8_t r_packet[0]; }; struct ciphers { struct cipher_list *c_cipher; unsigned char c_spec[4]; int c_speclen; struct ciphers *c_next; }; static struct tc *_sockopts[65536]; static struct tc_sess _sessions; static struct ciphers _ciphers_pkey; static struct ciphers _ciphers_sym; static struct freelist _free_free; static struct freelist _free_tc; static struct freelist _free_conn; static struct tc_cipher_spec _pkey[MAX_CIPHERS]; static int _pkey_len; static struct tc_scipher _sym[MAX_CIPHERS]; static int _sym_len; typedef int (*opt_cb)(struct tc *tc, int tcpop, int subop, int len, void *data); static void *get_free(struct freelist *f, unsigned int sz) { struct freelist *x = f->f_next; void *o; if (x) { o = x->f_obj; f->f_next = x->f_next; if (f != &_free_free) { x->f_next = _free_free.f_next; _free_free.f_next = x; x->f_obj = x; } } else { xprintf(XP_DEBUG, "Gotta malloc %u\n", sz); o = xmalloc(sz); } return o; } static void put_free(struct freelist *f, void *obj) { struct freelist *x = get_free(&_free_free, sizeof(*f)); x->f_obj = obj; x->f_next = f->f_next; f->f_next = x; } static struct tc *get_tc(void) { return get_free(&_free_tc, sizeof(struct tc)); } static void put_tc(struct tc *tc) { put_free(&_free_tc, tc); } static struct conn *get_connection(void) { return get_free(&_free_conn, sizeof(struct conn)); } static void put_connection(struct conn *c) { put_free(&_free_conn, c); } static void do_add_ciphers(struct ciphers *c, void *spec, int *speclen, int sz, void *specend) { uint8_t *p = (uint8_t*) spec + *speclen; c = c->c_next; while (c) { unsigned char *sp = c->c_spec; assert(p + sz <= (uint8_t*) specend); memcpy(p, sp, sz); p += sz; *speclen += sz; c = c->c_next; } } static int bad_packet(char *msg) { xprintf(XP_ALWAYS, "%s\n", msg); return 0; } static void tc_init(struct tc *tc) { memset(tc, 0, sizeof(*tc)); tc->tc_state = _conf.cf_disable ? STATE_DISABLED : STATE_CLOSED; tc->tc_mtu = TC_MTU; tc->tc_mss_clamp = 40; /* XXX */ tc->tc_sack_disable = 1; tc->tc_rto = 100 * 1000; /* XXX */ tc->tc_nocache = _conf.cf_nocache; tc->tc_ciphers_pkey = _pkey; tc->tc_ciphers_pkey_len = _pkey_len; tc->tc_ciphers_sym = _sym; tc->tc_ciphers_sym_len = _sym_len; } /* XXX */ static void tc_reset(struct tc *tc) { struct conn *c = tc->tc_conn; assert(c); tc_init(tc); tc->tc_conn = c; } static void kill_retransmit(struct tc *tc) { if (!tc->tc_retransmit) return; clear_timer(tc->tc_retransmit->r_timer); free(tc->tc_retransmit); tc->tc_retransmit = NULL; } static void crypto_free_keyset(struct tc *tc, struct tc_keyset *ks) { if (ks->tc_alg_tx) crypt_sym_destroy(ks->tc_alg_tx); if (ks->tc_alg_rx) crypt_sym_destroy(ks->tc_alg_rx); } static void tc_finish(struct tc *tc) { if (tc->tc_crypt_pub) crypt_pub_destroy(tc->tc_crypt_pub); if (tc->tc_crypt_sym) crypt_sym_destroy(tc->tc_crypt_sym); crypto_free_keyset(tc, &tc->tc_key_current); crypto_free_keyset(tc, &tc->tc_key_next); kill_retransmit(tc); if (tc->tc_last_ack_timer) clear_timer(tc->tc_last_ack_timer); if (tc->tc_sess) tc->tc_sess->ts_used = 0; } static struct tc *tc_dup(struct tc *tc) { struct tc *x = get_tc(); assert(x); *x = *tc; assert(!x->tc_crypt); assert(!x->tc_crypt_ops); return x; } static void do_expand(struct tc *tc, uint8_t tag, struct stuff *out) { int len = tc->tc_crypt_pub->cp_k_len; assert(len <= sizeof(out->s_data)); crypt_expand(tc->tc_crypt_pub->cp_hkdf, &tag, sizeof(tag), out->s_data, len); out->s_len = len; } static void compute_nextk(struct tc *tc, struct stuff *out) { do_expand(tc, CONST_NEXTK, out); } static void compute_mk(struct tc *tc, struct stuff *out) { int len = tc->tc_crypt_pub->cp_k_len; unsigned char tag[2]; unsigned char app_support = 0; int pos = tc->tc_role == ROLE_SERVER ? 1 : 0; assert(len <= sizeof(out->s_data)); app_support |= (tc->tc_app_support & 1) << pos; app_support |= (tc->tc_app_support >> 1) << (!pos); tag[0] = CONST_REKEY; tag[1] = app_support; crypt_expand(tc->tc_crypt_pub->cp_hkdf, tag, sizeof(tag), out->s_data, len); out->s_len = len; } static void compute_sid(struct tc *tc, struct stuff *out) { do_expand(tc, CONST_SESSID, out); } static void set_expand_key(struct tc *tc, struct stuff *s) { crypt_set_key(tc->tc_crypt_pub->cp_hkdf, s->s_data, s->s_len); } static void session_cache(struct tc *tc) { struct tc_sess *s = tc->tc_sess; if (tc->tc_nocache) return; if (!s) { s = xmalloc(sizeof(*s)); if (!s) err(1, "malloc()"); memset(s, 0, sizeof(*s)); s->ts_next = _sessions.ts_next; _sessions.ts_next = s; tc->tc_sess = s; s->ts_dir = tc->tc_dir; s->ts_role = tc->tc_role; s->ts_ip = tc->tc_dst_ip; s->ts_port = tc->tc_dst_port; s->ts_pub = crypt_new(tc->tc_crypt_pub->cp_ctr); s->ts_sym = crypt_new(tc->tc_crypt_sym->cs_ctr); } set_expand_key(tc, &tc->tc_nk); profile_add(1, "session_cache crypto_mac_set_key"); compute_sid(tc, &s->ts_sid); profile_add(1, "session_cache compute_sid"); compute_mk(tc, &s->ts_mk); profile_add(1, "session_cache compute_mk"); compute_nextk(tc, &s->ts_nk); profile_add(1, "session_cache compute_nk"); } static void init_algo(struct tc *tc, struct crypt_sym *cs, struct crypt_sym **algo, struct tc_keys *keys) { *algo = crypt_new(cs->cs_ctr); cs = *algo; crypt_set_key(cs->cs_cipher, keys->tk_enc.s_data, keys->tk_enc.s_len); crypt_set_key(cs->cs_mac, keys->tk_mac.s_data, keys->tk_mac.s_len); crypt_set_key(cs->cs_ack_mac, keys->tk_ack.s_data, keys->tk_ack.s_len); } static void compute_asm_keys(struct tc *tc, struct tc_keys *tk) { set_expand_key(tc, &tk->tk_prk); do_expand(tc, CONST_KEY_ENC, &tk->tk_enc); do_expand(tc, CONST_KEY_MAC, &tk->tk_mac); do_expand(tc, CONST_KEY_ACK, &tk->tk_ack); } static void compute_keys(struct tc *tc, struct tc_keyset *out) { struct crypt_sym **tx, **rx; set_expand_key(tc, &tc->tc_mk); profile_add(1, "compute keys mac set key"); do_expand(tc, CONST_KEY_C, &out->tc_client.tk_prk); do_expand(tc, CONST_KEY_S, &out->tc_server.tk_prk); profile_add(1, "compute keys calculated keys"); compute_asm_keys(tc, &out->tc_client); compute_asm_keys(tc, &out->tc_server); switch (tc->tc_role) { case ROLE_CLIENT: tx = &out->tc_alg_tx; rx = &out->tc_alg_rx; break; case ROLE_SERVER: tx = &out->tc_alg_rx; rx = &out->tc_alg_tx; break; default: assert(!"Unknown role"); abort(); break; } init_algo(tc, tc->tc_crypt_sym, tx, &out->tc_client); init_algo(tc, tc->tc_crypt_sym, rx, &out->tc_server); profile_add(1, "initialized algos"); } static void get_algo_info(struct tc *tc) { tc->tc_mac_size = tc->tc_crypt_sym->cs_mac_len; tc->tc_sym_ivmode = IVMODE_SEQ; /* XXX */ } static void scrub_sensitive(struct tc *tc) { } static void copy_stuff(struct stuff *dst, struct stuff *src) { memcpy(dst, src, sizeof(*dst)); } static int session_resume(struct tc *tc) { struct tc_sess *s = tc->tc_sess; if (!s) return 0; copy_stuff(&tc->tc_sid, &s->ts_sid); copy_stuff(&tc->tc_mk, &s->ts_mk); copy_stuff(&tc->tc_nk, &s->ts_nk); tc->tc_role = s->ts_role; tc->tc_crypt_sym = crypt_new(s->ts_sym->cs_ctr); tc->tc_crypt_pub = crypt_new(s->ts_pub->cp_ctr); return 1; } static void enable_encryption(struct tc *tc) { profile_add(1, "enable_encryption in"); tc->tc_state = STATE_ENCRYPTING; if (!session_resume(tc)) { set_expand_key(tc, &tc->tc_ss); profile_add(1, "enable_encryption mac set key"); compute_sid(tc, &tc->tc_sid); profile_add(1, "enable_encryption compute SID"); compute_mk(tc, &tc->tc_mk); profile_add(1, "enable_encryption compute mk"); compute_nextk(tc, &tc->tc_nk); profile_add(1, "enable_encryption did compute_nextk"); } compute_keys(tc, &tc->tc_key_current); profile_add(1, "enable_encryption compute keys"); get_algo_info(tc); session_cache(tc); profile_add(1, "enable_encryption session cache"); scrub_sensitive(tc); } static int conn_hash(uint16_t src, uint16_t dst) { return (src + dst) % (sizeof(_connection_map) / sizeof(*_connection_map)); } static struct conn *get_head(uint16_t src, uint16_t dst) { return _connection_map[conn_hash(src, dst)]; } static struct tc *do_lookup_connection_prev(struct sockaddr_in *src, struct sockaddr_in *dst, struct conn **prev) { struct conn *head; struct conn *c; head = get_head(src->sin_port, dst->sin_port); if (!head) return NULL; c = head->c_next; *prev = head; while (c) { if ( src->sin_addr.s_addr == c->c_addr[0].sin_addr.s_addr && dst->sin_addr.s_addr == c->c_addr[1].sin_addr.s_addr && src->sin_port == c->c_addr[0].sin_port && dst->sin_port == c->c_addr[1].sin_port) return c->c_tc; *prev = c; c = c->c_next; } return NULL; } static struct tc *lookup_connection_prev(struct ip *ip, struct tcphdr *tcp, int flags, struct conn **prev) { struct sockaddr_in addr[2]; int idx = flags & DF_IN ? 1 : 0; addr[idx].sin_addr.s_addr = ip->ip_src.s_addr; addr[idx].sin_port = tcp->th_sport; addr[!idx].sin_addr.s_addr = ip->ip_dst.s_addr; addr[!idx].sin_port = tcp->th_dport; return do_lookup_connection_prev(&addr[0], &addr[1], prev); } static struct tc *lookup_connection(struct ip *ip, struct tcphdr *tcp, int flags) { struct conn *prev; return lookup_connection_prev(ip, tcp, flags, &prev); } static struct tc *sockopt_find_port(int port) { return _sockopts[port]; } static struct tc *sockopt_find(struct tcpcrypt_ctl *ctl) { struct ip ip; struct tcphdr tcp; if (!ctl->tcc_dport) return sockopt_find_port(ctl->tcc_sport); /* XXX */ ip.ip_src = ctl->tcc_src; ip.ip_dst = ctl->tcc_dst; tcp.th_sport = ctl->tcc_sport; tcp.th_dport = ctl->tcc_dport; return lookup_connection(&ip, &tcp, 0); } static void sockopt_clear(unsigned short port) { _sockopts[port] = NULL; } static void retransmit(void *a) { struct tc *tc = a; struct ip *ip; xprintf(XP_DEBUG, "Retransmitting %p\n", tc); assert(tc->tc_retransmit); if (tc->tc_retransmit->r_num++ >= 10) { xprintf(XP_DEFAULT, "Retransmit timeout\n"); tc->tc_tcp_state = TCPSTATE_DEAD; /* XXX remove connection */ } ip = (struct ip*) tc->tc_retransmit->r_packet; divert_inject(ip, ntohs(ip->ip_len)); /* XXX decay */ tc->tc_retransmit->r_timer = add_timer(tc->tc_rto, retransmit, tc); } static void add_connection(struct conn *c) { int idx = c->c_addr[0].sin_port; struct conn *head; idx = conn_hash(c->c_addr[0].sin_port, c->c_addr[1].sin_port); if (!_connection_map[idx]) { _connection_map[idx] = xmalloc(sizeof(*c)); memset(_connection_map[idx], 0, sizeof(*c)); } head = _connection_map[idx]; c->c_next = head->c_next; head->c_next = c; } static struct tc *new_connection(struct ip *ip, struct tcphdr *tcp, int flags) { struct tc *tc; struct conn *c; int idx = flags & DF_IN ? 1 : 0; c = get_connection(); assert(c); profile_add(2, "alloc connection"); memset(c, 0, sizeof(*c)); c->c_addr[idx].sin_addr.s_addr = ip->ip_src.s_addr; c->c_addr[idx].sin_port = tcp->th_sport; c->c_addr[!idx].sin_addr.s_addr = ip->ip_dst.s_addr; c->c_addr[!idx].sin_port = tcp->th_dport; profile_add(2, "setup connection"); tc = sockopt_find_port(c->c_addr[0].sin_port); if (!tc) { tc = get_tc(); assert(tc); profile_add(2, "TC malloc"); tc_init(tc); profile_add(2, "TC init"); } else { /* For servers, we gotta duplicate options on child sockets. * For clients, we just steal it. */ if (flags & DF_IN) tc = tc_dup(tc); else sockopt_clear(c->c_addr[0].sin_port); } tc->tc_dst_ip.s_addr = c->c_addr[1].sin_addr.s_addr; tc->tc_dst_port = c->c_addr[1].sin_port; tc->tc_conn = c; c->c_tc = tc; add_connection(c); return tc; } static void do_remove_connection(struct tc *tc, struct conn *prev) { struct conn *item; assert(tc); assert(prev); item = prev->c_next; assert(item); tc_finish(tc); put_tc(tc); prev->c_next = item->c_next; put_connection(item); } static void remove_connection(struct ip *ip, struct tcphdr *tcp, int flags) { struct conn *prev = NULL; struct tc *tc; tc = lookup_connection_prev(ip, tcp, flags, &prev); do_remove_connection(tc, prev); } static void kill_connection(struct tc *tc) { struct conn *c = tc->tc_conn; struct conn *prev; struct tc *found; assert(c); found = do_lookup_connection_prev(&c->c_addr[0], &c->c_addr[1], &prev); assert(found); assert(found == tc); do_remove_connection(tc, prev); } static void last_ack(void *a) { struct tc *tc = a; tc->tc_last_ack_timer = NULL; xprintf(XP_NOISY, "Last ack for %p\n"); kill_connection(tc); } static void *tcp_data(struct tcphdr *tcp) { return (char*) tcp + (tcp->th_off << 2); } static int tcp_data_len(struct ip *ip, struct tcphdr *tcp) { int hl = (ip->ip_hl << 2) + (tcp->th_off << 2); return ntohs(ip->ip_len) - hl; } static void *find_opt(struct tcphdr *tcp, unsigned char opt) { unsigned char *p = (unsigned char*) (tcp + 1); int len = (tcp->th_off << 2) - sizeof(*tcp); int o, l; assert(len >= 0); while (len > 0) { if (*p == opt) { if (*(p + 1) > len) { xprintf(XP_ALWAYS, "fek\n"); return NULL; } return p; } o = *p++; len--; switch (o) { case TCPOPT_EOL: case TCPOPT_NOP: continue; } if (!len) { xprintf(XP_ALWAYS, "fuck\n"); return NULL; } l = *p++; len--; if (l > (len + 2) || l < 2) { xprintf(XP_ALWAYS, "fuck2 %d %d\n", l, len); return NULL; } p += l - 2; len -= l - 2; } assert(len == 0); return NULL; } static struct tc_subopt *find_subopt(struct tcphdr *tcp, unsigned char op) { struct tcpopt_crypt *toc; struct tc_subopt *tcs; int len; int optlen; toc = find_opt(tcp, TCPOPT_CRYPT); if (!toc) return NULL; len = toc->toc_len - sizeof(*toc); assert(len >= 0); if (len == 0 && op == TCOP_HELLO) return (struct tc_subopt*) 0xbad; tcs = &toc->toc_opts[0]; while (len > 0) { if (len < 1) return NULL; if (tcs->tcs_op <= 0x3f) optlen = 1; else if (tcs->tcs_op >= 0x80) { switch (tcs->tcs_op) { case TCOP_NEXTK1: case TCOP_NEXTK1_SUPPORT: optlen = 10; break; case TCOP_REKEY: /* XXX depends on cipher */ optlen = sizeof(struct tco_rekeystream); break; default: errx(1, "Unknown option %d", tcs->tcs_op); break; } } else optlen = tcs->tcs_len; if (optlen > len) return NULL; if (tcs->tcs_op == op) return tcs; len -= optlen; tcs = (struct tc_subopt*) ((unsigned long) tcs + optlen); } assert(len == 0); return NULL; } static void checksum_packet(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { checksum_ip(ip); checksum_tcp(tc, ip, tcp); } static void set_ip_len(struct ip *ip, unsigned short len) { unsigned short old = ntohs(ip->ip_len); int diff; int sum; ip->ip_len = htons(len); diff = len - old; sum = ntohs(~ip->ip_sum); sum += diff; sum = (sum >> 16) + (sum & 0xffff); sum += (sum >> 16); ip->ip_sum = htons(~sum); } static int foreach_subopt(struct tc *tc, int len, void *data, opt_cb cb) { struct tc_subopt *tcs = (struct tc_subopt*) data; int optlen = 0; unsigned char *d; assert(len >= 0); if (len == 0) return cb(tc, -1, TCOP_HELLO, optlen, tcs); while (len > 0) { d = (unsigned char *) tcs; if (len < 1) goto __bad; if (tcs->tcs_op <= 0x3f) optlen = 1; else if (tcs->tcs_op >= 0x80) { d++; switch (tcs->tcs_op) { case TCOP_NEXTK1: case TCOP_NEXTK1_SUPPORT: optlen = 10; break; case TCOP_REKEY: /* XXX depends on cipher */ optlen = sizeof(struct tco_rekeystream); break; default: errx(1, "Unknown option %d", tcs->tcs_op); break; } } else { if (len < 2) goto __bad; optlen = tcs->tcs_len; d = tcs->tcs_data; } if (optlen > len) goto __bad; if (cb(tc, -1, tcs->tcs_op, optlen, d)) return 1; len -= optlen; tcs = (struct tc_subopt*) ((unsigned long) tcs + optlen); } assert(len == 0); return 0; __bad: xprintf(XP_ALWAYS, "bad\n"); return 1; } static void foreach_opt(struct tc *tc, struct tcphdr *tcp, opt_cb cb) { unsigned char *p = (unsigned char*) (tcp + 1); int len = (tcp->th_off << 2) - sizeof(*tcp); int o, l; assert(len >= 0); while (len > 0) { o = *p++; len--; switch (o) { case TCPOPT_EOL: case TCPOPT_NOP: continue; /* XXX optimize */ l = 0; break; default: if (!len) { xprintf(XP_ALWAYS, "fuck\n"); return; } l = *p++; len--; if (l < 2 || l > (len + 2)) { xprintf(XP_ALWAYS, "fuck2 %d %d\n", l, len); return; } l -= 2; break; } if (o == TCPOPT_CRYPT) { if (foreach_subopt(tc, l, p, cb)) return; } else { if (cb(tc, o, -1, l, p)) return; } p += l; len -= l; } assert(len == 0); } static int do_ops_len(struct tc *tc, int tcpop, int subop, int len, void *data) { tc->tc_optlen += len + 2; return 0; } static int tcp_ops_len(struct tc *tc, struct tcphdr *tcp) { int nops = 40; uint8_t *p = (uint8_t*) (tcp + 1); tc->tc_optlen = 0; foreach_opt(tc, tcp, do_ops_len); nops -= tc->tc_optlen; p += tc->tc_optlen; assert(nops >= 0); while (nops--) { if (*p != TCPOPT_NOP && *p != TCPOPT_EOL) return (tcp->th_off << 2) - 20; p++; } return tc->tc_optlen; } static void *tcp_opts_alloc(struct tc *tc, struct ip *ip, struct tcphdr *tcp, int len) { int opslen = (tcp->th_off << 2) + len; int pad = opslen % 4; char *p; int dlen = ntohs(ip->ip_len) - (ip->ip_hl << 2) - (tcp->th_off << 2); int ol = (tcp->th_off << 2) - sizeof(*tcp); assert(len); /* find space in tail if full of nops */ if (ol == 40) { ol = tcp_ops_len(tc, tcp); assert(ol <= 40); if (40 - ol >= len) return (uint8_t*) (tcp + 1) + ol; } if (pad) len += 4 - pad; if (ntohs(ip->ip_len) + len > tc->tc_mtu) return NULL; p = (char*) tcp + (tcp->th_off << 2); memmove(p + len, p, dlen); memset(p, 0, len); assert(((tcp->th_off << 2) + len) <= 60); set_ip_len(ip, ntohs(ip->ip_len) + len); tcp->th_off += len >> 2; return p; } static struct tc_subopt *subopt_alloc(struct tc *tc, struct ip *ip, struct tcphdr *tcp, int len) { struct tcpopt_crypt *toc; len += sizeof(*toc); toc = tcp_opts_alloc(tc, ip, tcp, len); if (!toc) return NULL; toc->toc_kind = TCPOPT_CRYPT; toc->toc_len = len; return toc->toc_opts; } static struct tc_sess *session_find_host(struct tc *tc, struct in_addr *in, int port) { struct tc_sess *s = _sessions.ts_next; while (s) { /* we're liberal - lets only check host */ if (!s->ts_used && (s->ts_dir == tc->tc_dir) && (s->ts_ip.s_addr == in->s_addr)) return s; s = s->ts_next; } return NULL; } static int do_output_closed(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tc_sess *ts = tc->tc_sess; tc->tc_dir = DIR_OUT; if (tcp->th_flags != TH_SYN) return DIVERT_ACCEPT; if (!ts && !tc->tc_nocache) ts = session_find_host(tc, &ip->ip_dst, tcp->th_dport); if (!ts) { struct tcpopt_crypt *toc; int len = sizeof(*toc); if (tc->tc_app_support) len++; toc = tcp_opts_alloc(tc, ip, tcp, len); if (!toc) { xprintf(XP_ALWAYS, "No space for hello\n"); tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } toc->toc_kind = TCPOPT_CRYPT; toc->toc_len = len; if (tc->tc_app_support) toc->toc_opts[0].tcs_op = TCOP_HELLO_SUPPORT; tc->tc_state = STATE_HELLO_SENT; if (!_conf.cf_nocache) xprintf(XP_DEBUG, "Can't find session for host\n"); } else { /* session caching */ struct tc_subopt *tcs; int len = 1 + sizeof(struct tc_sid); tcs = subopt_alloc(tc, ip, tcp, len); if (!tcs) { xprintf(XP_ALWAYS, "No space for NEXTK1\n"); tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } tcs->tcs_op = tc->tc_app_support ? TCOP_NEXTK1_SUPPORT : TCOP_NEXTK1; assert(ts->ts_sid.s_len >= sizeof(struct tc_sid)); memcpy(&tcs->tcs_len, &ts->ts_sid.s_data, sizeof(struct tc_sid)); tc->tc_state = STATE_NEXTK1_SENT; assert(!ts->ts_used || ts == tc->tc_sess); tc->tc_sess = ts; ts->ts_used = 1; } return DIVERT_MODIFY; } static int do_output_hello_rcvd(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tc_subopt *tcs; int len; if (tc->tc_cmode == CMODE_ALWAYS) { tcs = subopt_alloc(tc, ip, tcp, 1); if (!tcs) { xprintf(XP_ALWAYS, "No space for HELLO\n"); tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } tcs->tcs_op = TCOP_HELLO; tc->tc_state = STATE_HELLO_SENT; return DIVERT_MODIFY; } len = sizeof(*tcs) + tc->tc_ciphers_pkey_len; tcs = subopt_alloc(tc, ip, tcp, len); if (!tcs) { xprintf(XP_ALWAYS, "No space for PKCONF\n"); tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } tcs->tcs_op = (tc->tc_app_support & 1) ? TCOP_PKCONF_SUPPORT : TCOP_PKCONF; tcs->tcs_len = len; memcpy(tcs->tcs_data, tc->tc_ciphers_pkey, tc->tc_ciphers_pkey_len); memcpy(tc->tc_pub_cipher_list, tc->tc_ciphers_pkey, tc->tc_ciphers_pkey_len); tc->tc_pub_cipher_list_len = tc->tc_ciphers_pkey_len; tc->tc_state = STATE_PKCONF_SENT; return DIVERT_MODIFY; } static void *data_alloc(struct tc *tc, struct ip *ip, struct tcphdr *tcp, int len, int retx) { int totlen = ntohs(ip->ip_len); int hl = (ip->ip_hl << 2) + (tcp->th_off << 2); void *p; assert(totlen == hl); p = (char*) tcp + (tcp->th_off << 2); totlen += len; assert(totlen <= 1500); set_ip_len(ip, totlen); if (!retx) tc->tc_seq_off = len; return p; } static void do_random(void *p, int len) { uint8_t *x = p; while (len--) *x++ = rand() & 0xff; } static void generate_nonce(struct tc *tc, int len) { profile_add(1, "generated nonce in"); assert(tc->tc_nonce_len == 0); tc->tc_nonce_len = len; do_random(tc->tc_nonce, tc->tc_nonce_len); profile_add(1, "generated nonce out"); } static int do_output_pkconf_rcvd(struct tc *tc, struct ip *ip, struct tcphdr *tcp, int retx) { struct tc_subopt *tcs; int len, klen; struct tc_init1 *init1; void *key; uint8_t *p; if (!retx) generate_nonce(tc, tc->tc_crypt_pub->cp_n_c); tcs = subopt_alloc(tc, ip, tcp, 1); assert(tcs); tcs->tcs_op = TCOP_INIT1; klen = crypt_get_key(tc->tc_crypt_pub->cp_pub, &key); len = sizeof(*init1) + tc->tc_ciphers_sym_len + tc->tc_nonce_len + klen; init1 = data_alloc(tc, ip, tcp, len, retx); init1->i1_magic = htonl(TC_INIT1); init1->i1_len = htonl(len); init1->i1_pub = tc->tc_cipher_pkey; init1->i1_num_ciphers = htons(tc->tc_ciphers_sym_len / sizeof(*tc->tc_ciphers_sym)); p = (uint8_t*) init1->i1_ciphers; memcpy(p, tc->tc_ciphers_sym, tc->tc_ciphers_sym_len); p += tc->tc_ciphers_sym_len; memcpy(tc->tc_sym_cipher_list, tc->tc_ciphers_sym, tc->tc_ciphers_sym_len); tc->tc_sym_cipher_list_len = tc->tc_ciphers_sym_len; memcpy(p, tc->tc_nonce, tc->tc_nonce_len); p += tc->tc_nonce_len; memcpy(p, key, klen); tc->tc_state = STATE_INIT1_SENT; tc->tc_role = ROLE_CLIENT; assert(len <= sizeof(tc->tc_init1)); memcpy(tc->tc_init1, init1, len); tc->tc_init1_len = len; return DIVERT_MODIFY; } static int do_output_init1_rcvd(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { return DIVERT_ACCEPT; } static int do_output_init2_sent(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { /* we generated this packet */ struct tc_subopt *opt = find_subopt(tcp, TCOP_INIT2); /* kernel is getting pissed off and is resending SYN ack (because we're * delaying his connect setup) */ if (!opt) { /* we could piggy back / retx init2 */ assert(tcp_data_len(ip, tcp) == 0); assert(tcp->th_flags == (TH_SYN | TH_ACK)); assert(tc->tc_retransmit); /* XXX */ tcp = (struct tcphdr*) &tc->tc_retransmit->r_packet[20]; assert(find_subopt(tcp, TCOP_INIT2)); return DIVERT_DROP; } else { #if 1 enable_encryption(tc); #endif } return DIVERT_ACCEPT; } static void compute_mac_opts(struct tc *tc, struct tcphdr *tcp, struct iovec *iov, int *nump) { int optlen, ol, optlen2; uint8_t *p = (uint8_t*) (tcp + 1); int num = *nump; optlen2 = optlen = (tcp->th_off << 2) - sizeof(*tcp); assert(optlen >= 0); if (optlen == tc->tc_mac_opt_cache[tc->tc_dir_packet]) return; iov[num].iov_base = NULL; while (optlen > 0) { ol = 0; switch (*p) { case TCPOPT_EOL: case TCPOPT_NOP: ol = 1; ol = 1; break; default: if (optlen < 2) { xprintf(XP_ALWAYS, "death\n"); abort(); } ol = *(p + 1); if (ol > optlen) { xprintf(XP_ALWAYS, "fuck off\n"); abort(); } } switch (*p) { case TCPOPT_TIMESTAMP: case TCPOPT_SKEETER: case TCPOPT_BUBBA: case TCPOPT_MD5: case TCPOPT_MAC: case TCPOPT_EOL: case TCPOPT_NOP: if (iov[num].iov_base) { num++; iov[num].iov_base = NULL; } break; default: if (!iov[num].iov_base) { iov[num].iov_base = p; iov[num].iov_len = 0; } iov[num].iov_len += ol; break; } optlen -= ol; p += ol; } if (iov[num].iov_base) num++; if (*nump == num) tc->tc_mac_opt_cache[tc->tc_dir_packet] = optlen2; *nump = num; } static void compute_mac(struct tc *tc, struct ip *ip, struct tcphdr *tcp, void *iv, void *out, int dir_in) { struct mac_m m; struct iovec iov[32]; int num = 0; struct mac_a a; uint8_t *outp; int maca_len = tc->tc_mac_size; uint8_t *mac = alloca(maca_len); int maclen; uint32_t *p1, *p2; uint64_t seq = tc->tc_seq + ntohl(tcp->th_seq); uint64_t ack = tc->tc_ack + ntohl(tcp->th_ack); struct crypt_sym *cs = dir_in ? tc->tc_key_active->tc_alg_rx : tc->tc_key_active->tc_alg_tx; seq -= dir_in ? tc->tc_isn_peer : tc->tc_isn; ack -= dir_in ? tc->tc_isn : tc->tc_isn_peer; assert(mac); p2 = (uint32_t*) mac; /* M struct */ m.mm_magic = htons(MACM_MAGIC); m.mm_len = htons(ntohs(ip->ip_len) - (ip->ip_hl << 2)); m.mm_off = tcp->th_off; m.mm_flags = tcp->th_flags; m.mm_urg = tcp->th_urp; m.mm_seqhi = htonl(seq >> 32); m.mm_seq = htonl(seq & 0xFFFFFFFF); iov[num].iov_base = &m; iov[num++].iov_len = sizeof(m); /* options */ compute_mac_opts(tc, tcp, iov, &num); assert(num < sizeof(iov) / sizeof(*iov)); /* IV */ if (tc->tc_mac_ivlen) { if (!iv) { assert(!"implement"); // crypto_next_iv(tc, out, &tc->tc_mac_ivlen); iv = out; out = (void*) ((unsigned long) out + tc->tc_mac_ivlen); } iov[num].iov_base = iv; iov[num++].iov_len = tc->tc_mac_ivlen; } else assert(!iv); /* payload */ assert(num < sizeof(iov) / sizeof(*iov)); iov[num].iov_len = tcp_data_len(ip, tcp); if (iov[num].iov_len) iov[num++].iov_base = tcp_data(tcp); maclen = tc->tc_mac_size; profile_add(2, "compute_mac pre M"); crypt_mac(cs->cs_mac, iov, num, out, &maclen); profile_add(2, "compute_mac MACed M"); /* A struct */ a.ma_ackhi = htonl(ack >> 32); a.ma_ack = htonl(ack & 0xFFFFFFFF); memset(mac, 0, maca_len); iov[0].iov_base = &a; iov[0].iov_len = sizeof(a); crypt_mac(cs->cs_ack_mac, iov, 1, mac, &maca_len); assert(maca_len == tc->tc_mac_size); profile_add(2, "compute_mac MACed A"); /* XOR the two */ p1 = (uint32_t*) out; maclen = tc->tc_mac_size; while (maclen >= 4) { *p1++ ^= *p2++; maclen -= 4; } if (maclen == 0) return; outp = (uint8_t*) p1; mac = (uint8_t*) p2; while (maclen--) *outp++ ^= *mac++; } static void *get_iv(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { static uint64_t seq; void *iv = NULL; switch (tc->tc_sym_ivmode) { case IVMODE_CRYPT: assert(!"codeme"); break; case IVMODE_SEQ: seq = htonl(tc->tc_seq >> 32); seq <<= 32; seq |= tcp->th_seq; iv = &seq; break; case IVMODE_NONE: break; default: assert(!"sdfsfd"); break; } return iv; } static void encrypt(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { uint8_t *data = tcp_data(tcp); int dlen = tcp_data_len(ip, tcp); void *iv = NULL; struct crypt *c = tc->tc_key_active->tc_alg_tx->cs_cipher; iv = get_iv(tc, ip, tcp); if (dlen) crypt_encrypt(c, iv, data, dlen); } static int add_mac(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tcpopt_mac *tom; int len = sizeof(*tom) + tc->tc_mac_size + tc->tc_mac_ivlen; /* add MAC option */ tom = tcp_opts_alloc(tc, ip, tcp, len); if (!tom) return -1; tom->tom_kind = TCPOPT_MAC; tom->tom_len = len; compute_mac(tc, ip, tcp, NULL, tom->tom_data, 0); return 0; } static int fixup_seq(struct tc *tc, struct tcphdr *tcp, int in) { if (!tc->tc_seq_off) return 0; if (in) { tcp->th_ack = htonl(ntohl(tcp->th_ack) - tc->tc_seq_off); tcp->th_seq = htonl(ntohl(tcp->th_seq) - tc->tc_rseq_off); } else { tcp->th_seq = htonl(ntohl(tcp->th_seq) + tc->tc_seq_off); tcp->th_ack = htonl(ntohl(tcp->th_ack) + tc->tc_rseq_off); } return 1; } static int connected(struct tc *tc) { return tc->tc_state == STATE_ENCRYPTING || tc->tc_state == STATE_REKEY_SENT || tc->tc_state == STATE_REKEY_RCVD; } static int do_compress(struct tc *tc, int tcpop, int subop, int len, void *data) { uint8_t *p = data; len += 2; p -= 2; memcpy(&tc->tc_opt[tc->tc_optlen], p, len); tc->tc_optlen += len; assert(tc->tc_optlen <= sizeof(tc->tc_opt)); return 0; } static void compress_options(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int len; int max = 60; void *p; memset(tc->tc_opt, TCPOPT_EOL, sizeof(tc->tc_opt)); tc->tc_optlen = 0; foreach_opt(tc, tcp, do_compress); len = max - (tcp->th_off << 2); assert(len >= 0); if (len) { p = tcp_opts_alloc(tc, ip, tcp, len); assert(p); } memcpy(tcp + 1, tc->tc_opt, sizeof(tc->tc_opt)); } static void do_rekey(struct tc *tc) { assert(!tc->tc_key_next.tc_alg_rx); tc->tc_keygen++; assert(!"implement"); // crypto_mac_set_key(tc, tc->tc_mk.s_data, tc->tc_mk.s_len); compute_mk(tc, &tc->tc_mk); compute_keys(tc, &tc->tc_key_next); xprintf(XP_DEFAULT, "Rekeying, keygen %d [%p]\n", tc->tc_keygen, tc); } static int rekey_complete(struct tc *tc) { if (tc->tc_keygenrx != tc->tc_keygen) { assert((uint8_t)(tc->tc_keygenrx + 1) == tc->tc_keygen); return 0; } if (tc->tc_keygentx != tc->tc_keygen) { assert((uint8_t)(tc->tc_keygentx + 1) == tc->tc_keygen); return 0; } assert(tc->tc_key_current.tc_alg_tx); assert(tc->tc_key_next.tc_alg_tx); crypto_free_keyset(tc, &tc->tc_key_current); memcpy(&tc->tc_key_current, &tc->tc_key_next, sizeof(tc->tc_key_current)); memset(&tc->tc_key_next, 0, sizeof(tc->tc_key_next)); tc->tc_state = STATE_ENCRYPTING; xprintf(XP_DEBUG, "Rekey complete %d [%p]\n", tc->tc_keygen, tc); return 1; } static void rekey_output(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int rk = 0; struct tco_rekeystream *tr; /* got all old packets from the other dude, lets rekey our side */ if (tc->tc_state == STATE_REKEY_RCVD && ntohl(tcp->th_ack) >= tc->tc_rekey_seq) { xprintf(XP_DEBUG, "RX rekey done %d %p\n", tc->tc_keygen, tc); tc->tc_keygenrx++; assert(tc->tc_keygenrx == tc->tc_keygen); if (rekey_complete(tc)) return; tc->tc_state = STATE_REKEY_SENT; tc->tc_rekey_seq = ntohl(tcp->th_seq); tc->tc_sent_bytes = 0; } /* half way through rekey - figure out current key */ if (tc->tc_keygentx != tc->tc_keygenrx && tc->tc_keygentx == tc->tc_keygen) tc->tc_key_active = &tc->tc_key_next; /* XXX check if proto supports rekey */ if (!rk) return; /* initiate rekey */ if (tc->tc_sent_bytes > rk && tc->tc_state != STATE_REKEY_RCVD) { do_rekey(tc); tc->tc_sent_bytes = 0; tc->tc_rekey_seq = ntohl(tcp->th_seq); tc->tc_state = STATE_REKEY_SENT; } if (tc->tc_state != STATE_REKEY_SENT) return; /* old shit - send with old key */ if (ntohl(tcp->th_seq) < tc->tc_rekey_seq) { assert(ntohl(tcp->th_seq) + tcp_data_len(ip, tcp) <= tc->tc_rekey_seq); return; } /* send rekeys */ compress_options(tc, ip, tcp); tr = (struct tco_rekeystream*) subopt_alloc(tc, ip, tcp, sizeof(*tr)); assert(tr); tr->tr_op = TCOP_REKEY; tr->tr_key = tc->tc_keygen; tr->tr_seq = htonl(tc->tc_rekey_seq); tc->tc_key_active = &tc->tc_key_next; } static int do_output_encrypting(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { if (tcp->th_flags == (TH_SYN | TH_ACK)) { /* XXX I assume we just sent ACK to dude but he didn't get it * yet */ return DIVERT_DROP; } assert(!(tcp->th_flags & TH_SYN)); fixup_seq(tc, tcp, 0); tc->tc_key_active = &tc->tc_key_current; rekey_output(tc, ip, tcp); profile_add(1, "do_output pre sym encrypt"); encrypt(tc, ip, tcp); profile_add(1, "do_output post sym encrypt"); if (add_mac(tc, ip, tcp)) { /* hopefully pmtu disc works */ xprintf(XP_ALWAYS, "No space for MAC - dropping\n"); return DIVERT_DROP; } profile_add(1, "post add mac"); /* XXX retransmissions. approx. */ tc->tc_sent_bytes += tcp_data_len(ip, tcp); return DIVERT_MODIFY; } static int sack_disable(struct tc *tc, struct tcphdr *tcp) { struct { uint8_t kind; uint8_t len; } *sack; sack = find_opt(tcp, TCPOPT_SACK_PERMITTED); if (!sack) return DIVERT_ACCEPT; memset(sack, TCPOPT_NOP, sizeof(*sack)); return DIVERT_MODIFY; } static int do_tcp_output(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int rc = DIVERT_ACCEPT; if (tcp->th_flags & TH_SYN) tc->tc_isn = ntohl(tcp->th_seq); if (tcp->th_flags == TH_SYN) { if (tc->tc_tcp_state == TCPSTATE_LASTACK) { tc_finish(tc); tc_reset(tc); } rc = sack_disable(tc, tcp); } if (tcp->th_flags & TH_FIN) { switch (tc->tc_tcp_state) { case TCPSTATE_FIN1_RCVD: tc->tc_tcp_state = TCPSTATE_FIN2_SENT; break; case TCPSTATE_FIN2_SENT: break; default: tc->tc_tcp_state = TCPSTATE_FIN1_SENT; } return rc; } if (tcp->th_flags & TH_RST) { tc->tc_tcp_state = TCPSTATE_DEAD; return rc; } if (!(tcp->th_flags & TH_ACK)) return rc; switch (tc->tc_tcp_state) { case TCPSTATE_FIN2_RCVD: tc->tc_tcp_state = TCPSTATE_LASTACK; if (!tc->tc_last_ack_timer) tc->tc_last_ack_timer = add_timer(10 * 1000 * 1000, last_ack, tc); else xprintf(XP_DEFAULT, "uarning\n"); break; } return rc; } static int do_output_nextk1_rcvd(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tc_subopt *tcs; if (!tc->tc_sess) return do_output_hello_rcvd(tc, ip, tcp); tcs = subopt_alloc(tc, ip, tcp, 1); if (!tcs) { xprintf(XP_ALWAYS, "No space for NEXTK2\n"); tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } tcs->tcs_op = (tc->tc_app_support & 1) ? TCOP_NEXTK2_SUPPORT : TCOP_NEXTK2; tc->tc_state = STATE_NEXTK2_SENT; return DIVERT_MODIFY; } static int do_output(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int rc = DIVERT_ACCEPT; int tcp_rc; tcp_rc = do_tcp_output(tc, ip, tcp); /* an RST half way through the handshake */ if (tc->tc_tcp_state == TCPSTATE_DEAD && !connected(tc)) return tcp_rc; switch (tc->tc_state) { case STATE_HELLO_SENT: case STATE_NEXTK1_SENT: /* syn re-TX. fallthrough */ assert(tcp->th_flags & TH_SYN); case STATE_CLOSED: rc = do_output_closed(tc, ip, tcp); break; case STATE_PKCONF_SENT: /* reTX of syn ack, or ACK (role switch) */ case STATE_HELLO_RCVD: rc = do_output_hello_rcvd(tc, ip, tcp); break; case STATE_NEXTK2_SENT: /* syn ack rtx */ assert(tc->tc_sess); assert(tcp->th_flags == (TH_SYN | TH_ACK)); case STATE_NEXTK1_RCVD: rc = do_output_nextk1_rcvd(tc, ip, tcp); break; case STATE_PKCONF_RCVD: rc = do_output_pkconf_rcvd(tc, ip, tcp, 0); break; case STATE_INIT1_RCVD: rc = do_output_init1_rcvd(tc, ip, tcp); break; case STATE_INIT1_SENT: if (!find_subopt(tcp, TCOP_INIT1)) rc = do_output_pkconf_rcvd(tc, ip, tcp, 1); break; case STATE_INIT2_SENT: rc = do_output_init2_sent(tc, ip, tcp); break; case STATE_ENCRYPTING: case STATE_REKEY_SENT: case STATE_REKEY_RCVD: rc = do_output_encrypting(tc, ip, tcp); break; case STATE_DISABLED: rc = DIVERT_ACCEPT; break; default: xprintf(XP_ALWAYS, "Unknown state %d\n", tc->tc_state); abort(); } if (rc == DIVERT_ACCEPT) return tcp_rc; return rc; } static struct tc_sess *session_find(struct tc *tc, struct tc_sid *sid) { struct tc_sess *s = _sessions.ts_next; while (s) { if (tc->tc_dir == s->ts_dir && memcmp(sid, s->ts_sid.s_data, sizeof(*sid)) == 0) return s; s = s->ts_next; } return NULL; } static int do_clamp_mss(struct tc *tc, uint16_t *mss) { int len; len = ntohs(*mss) - tc->tc_mss_clamp; assert(len > 0); *mss = htons(len); xprintf(XP_NOISY, "Clamping MSS to %d\n", len); return DIVERT_MODIFY; } static int opt_input_closed(struct tc *tc, int tcpop, int subop, int len, void *data) { uint8_t *p; profile_add(2, "opt_input_closed in"); switch (subop) { case TCOP_HELLO_SUPPORT: tc->tc_app_support |= 2; /* fallthrough */ case TCOP_HELLO: tc->tc_state = STATE_HELLO_RCVD; break; case TCOP_NEXTK1_SUPPORT: tc->tc_app_support |= 2; /* fallthrough */ case TCOP_NEXTK1: tc->tc_state = STATE_NEXTK1_RCVD; tc->tc_sess = session_find(tc, data); profile_add(2, "found session"); break; } switch (tcpop) { case TCPOPT_SACK_PERMITTED: p = data; p[-2] = TCPOPT_NOP; p[-1] = TCPOPT_NOP; tc->tc_verdict = DIVERT_MODIFY; break; case TCPOPT_MAXSEG: if (do_clamp_mss(tc, data) == DIVERT_MODIFY) tc->tc_verdict = DIVERT_MODIFY; tc->tc_mss_clamp = -1; break; } profile_add(2, "opt_input_closed out"); return 0; } static int do_input_closed(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { tc->tc_dir = DIR_IN; if (tcp->th_flags != TH_SYN) return DIVERT_ACCEPT; tc->tc_verdict = DIVERT_ACCEPT; tc->tc_state = STATE_DISABLED; profile_add(1, "do_input_closed pre option parse"); foreach_opt(tc, tcp, opt_input_closed); profile_add(1, "do_input_closed options parsed"); return tc->tc_verdict; } static int negotiate_cipher(struct tc *tc, struct tc_cipher_spec *a, int an) { struct tc_cipher_spec *b = tc->tc_ciphers_pkey; int bn = tc->tc_ciphers_pkey_len / sizeof(*tc->tc_ciphers_pkey); struct tc_cipher_spec *out = &tc->tc_cipher_pkey; tc->tc_pub_cipher_list_len = an * sizeof(*a); memcpy(tc->tc_pub_cipher_list, a, tc->tc_pub_cipher_list_len); while (an--) { while (bn--) { if (a->tcs_algo == b->tcs_algo) { out->tcs_algo = a->tcs_algo; return 1; } b++; } a++; } return 0; } static void make_reply(void *buf, struct ip *ip, struct tcphdr *tcp) { struct ip *ip2 = buf; struct tcphdr *tcp2; int dlen = ntohs(ip->ip_len) - (ip->ip_hl << 2) - (tcp->th_off << 2); ip2->ip_v = 4; ip2->ip_hl = sizeof(*ip2) >> 2; ip2->ip_tos = 0; ip2->ip_len = htons(sizeof(*ip2) + sizeof(*tcp2)); ip2->ip_id = 0; ip2->ip_off = 0; ip2->ip_ttl = 128; ip2->ip_p = IPPROTO_TCP; ip2->ip_sum = 0; ip2->ip_src = ip->ip_dst; ip2->ip_dst = ip->ip_src; tcp2 = (struct tcphdr*) (ip2 + 1); tcp2->th_sport = tcp->th_dport; tcp2->th_dport = tcp->th_sport; tcp2->th_seq = tcp->th_ack; tcp2->th_ack = htonl(ntohl(tcp->th_seq) + dlen); tcp2->th_x2 = 0; tcp2->th_off = sizeof(*tcp2) >> 2; tcp2->th_flags = TH_ACK; tcp2->th_win = tcp->th_win; tcp2->th_sum = 0; tcp2->th_urp = 0; } static void *alloc_retransmit(struct tc *tc) { struct retransmit *r; int len; assert(!tc->tc_retransmit); len = sizeof(*r) + tc->tc_mtu; r = xmalloc(len); memset(r, 0, len); r->r_timer = add_timer(tc->tc_rto, retransmit, tc); tc->tc_retransmit = r; return r->r_packet; } static void init_pkey(struct tc *tc) { struct ciphers *c = _ciphers_pkey.c_next; struct tc_cipher_spec *s; assert(tc->tc_cipher_pkey.tcs_algo); while (c) { s = (struct tc_cipher_spec*) c->c_spec; if (s->tcs_algo == tc->tc_cipher_pkey.tcs_algo) { tc->tc_crypt_pub = crypt_new(c->c_cipher->c_ctr); return; } c = c->c_next; } assert(!"Can't init cipher"); } static int do_input_hello_sent(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tc_subopt *tcs; struct tc_cipher_spec *cipher; tcs = find_subopt(tcp, TCOP_HELLO); if (tcs) { if (tc->tc_cmode == CMODE_ALWAYS) { tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } tc->tc_state = STATE_HELLO_RCVD; return DIVERT_ACCEPT; } if ((tcs = find_subopt(tcp, TCOP_PKCONF_SUPPORT))) tc->tc_app_support |= 2; else { tcs = find_subopt(tcp, TCOP_PKCONF); if (!tcs) { tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } } assert((tcs->tcs_len - 2) % sizeof(*cipher) == 0); cipher = (struct tc_cipher_spec*) tcs->tcs_data; if (!negotiate_cipher(tc, cipher, (tcs->tcs_len - 2) / sizeof(*cipher))) { xprintf(XP_ALWAYS, "No cipher\n"); tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } init_pkey(tc); tc->tc_state = STATE_PKCONF_RCVD; /* we switched roles, we gotta inject the INIT1 */ if (tcp->th_flags != (TH_SYN | TH_ACK)) { void *buf; struct ip *ip2; struct tcphdr *tcp2; buf = alloc_retransmit(tc); make_reply(buf, ip, tcp); ip2 = (struct ip*) buf; tcp2 = (struct tcphdr*) (ip2 + 1); do_output_pkconf_rcvd(tc, ip2, tcp2, 0); checksum_packet(tc, ip2, tcp2); divert_inject(ip2, ntohs(ip2->ip_len)); tc->tc_state = STATE_INIT1_SENT; } return DIVERT_ACCEPT; } static void do_neg_sym(struct tc *tc, struct ciphers *c, struct tc_scipher *a) { struct tc_scipher *b; c = c->c_next; while (c) { b = (struct tc_scipher*) c->c_spec; if (b->sc_algo == a->sc_algo) { tc->tc_crypt_sym = crypt_new(c->c_cipher->c_ctr); tc->tc_cipher_sym.sc_algo = a->sc_algo; break; } c = c->c_next; } } static int negotiate_sym_cipher(struct tc *tc, struct tc_scipher *a, int alen) { int rc = 0; tc->tc_sym_cipher_list_len = alen * sizeof(*a); memcpy(tc->tc_sym_cipher_list, a, tc->tc_sym_cipher_list_len); while (alen--) { do_neg_sym(tc, &_ciphers_sym, a); if (tc->tc_crypt_sym) { rc = 1; break; } a++; } return rc; } static int select_pkey(struct tc *tc, struct tc_cipher_spec *pkey) { struct tc_cipher_spec *spec; struct ciphers *c = _ciphers_pkey.c_next; int i; /* check whether we know about the cipher */ while (c) { spec = (struct tc_cipher_spec*) c->c_spec; if (spec->tcs_algo == pkey->tcs_algo) { tc->tc_crypt_pub = crypt_new(c->c_cipher->c_ctr); break; } c = c->c_next; } if (!c) return 0; /* check whether we were willing to accept this cipher */ for (i = 0; i < tc->tc_ciphers_pkey_len / sizeof(*tc->tc_ciphers_pkey); i++) { spec = &tc->tc_ciphers_pkey[i]; if (spec->tcs_algo == pkey->tcs_algo) { tc->tc_cipher_pkey = *pkey; return 1; } } /* XXX cleanup */ return 0; } static void compute_ss(struct tc *tc) { struct iovec iov[5]; unsigned char num; profile_add(1, "compute ss in"); assert((tc->tc_pub_cipher_list_len % 3) == 0); num = tc->tc_pub_cipher_list_len / 3; iov[0].iov_base = &num; iov[0].iov_len = 1; iov[1].iov_base = tc->tc_pub_cipher_list; iov[1].iov_len = tc->tc_pub_cipher_list_len; iov[2].iov_base = tc->tc_init1; iov[2].iov_len = tc->tc_init1_len; iov[3].iov_base = tc->tc_init2; iov[3].iov_len = tc->tc_init2_len; iov[4].iov_base = tc->tc_pms; iov[4].iov_len = tc->tc_pms_len; crypt_set_key(tc->tc_crypt_pub->cp_hkdf, tc->tc_nonce, tc->tc_nonce_len); profile_add(1, "compute ss mac set key"); tc->tc_ss.s_len = sizeof(tc->tc_ss.s_data); crypt_extract(tc->tc_crypt_pub->cp_hkdf, iov, sizeof(iov) / sizeof(*iov), tc->tc_ss.s_data, &tc->tc_ss.s_len); assert(tc->tc_ss.s_len <= sizeof(tc->tc_ss.s_data)); profile_add(1, "compute ss did MAC"); } static int process_init1(struct tc *tc, struct ip *ip, struct tcphdr *tcp, uint8_t *kxs, int kxs_len) { struct tc_subopt *tcs; struct tc_init1 *i1; int dlen; uint8_t *nonce; int nonce_len; int num_ciphers; void *key; int klen; int cl; void *pms; int pmsl; tcs = find_subopt(tcp, TCOP_INIT1); if (!tcs) return bad_packet("can't find init1"); dlen = tcp_data_len(ip, tcp); i1 = tcp_data(tcp); if (dlen < sizeof(*i1)) return bad_packet("short init1"); if (ntohl(i1->i1_magic) != TC_INIT1) return bad_packet("bad magic"); if (dlen != ntohl(i1->i1_len)) return bad_packet("bad init1 lenn"); if (!select_pkey(tc, &i1->i1_pub)) return bad_packet("init1: bad public key"); nonce_len = tc->tc_crypt_pub->cp_n_c; num_ciphers = ntohs(i1->i1_num_ciphers); klen = dlen - sizeof(*i1) - num_ciphers * sizeof(*i1->i1_ciphers) - nonce_len; if (klen <= 0) return bad_packet("bad init1 len"); if (tc->tc_crypt_pub->cp_max_key && klen > tc->tc_crypt_pub->cp_max_key) return bad_packet("init1: key length disagreement"); if (tc->tc_crypt_pub->cp_min_key && klen < tc->tc_crypt_pub->cp_min_key) return bad_packet("init2: key length too short"); if (!negotiate_sym_cipher(tc, i1->i1_ciphers, num_ciphers)) return bad_packet("init1: can't negotiate"); nonce = (uint8_t*) &i1->i1_ciphers[num_ciphers]; key = nonce + nonce_len; profile_add(1, "pre pkey set key"); /* figure out key len */ if (crypt_set_key(tc->tc_crypt_pub->cp_pub, key, klen) == -1) return 0; profile_add(1, "pkey set key"); generate_nonce(tc, tc->tc_crypt_pub->cp_n_s); /* XXX fix crypto api to have from to args */ memcpy(kxs, tc->tc_nonce, tc->tc_nonce_len); cl = crypt_encrypt(tc->tc_crypt_pub->cp_pub, NULL, kxs, tc->tc_nonce_len); assert(cl <= kxs_len); /* XXX too late to check */ pms = tc->tc_nonce; pmsl = tc->tc_nonce_len; if (tc->tc_crypt_pub->cp_key_agreement) { pms = alloca(1024); pmsl = crypt_compute_key(tc->tc_crypt_pub->cp_pub, pms); assert(pmsl < 1024); /* XXX */ } assert(dlen <= sizeof(tc->tc_init1)); memcpy(tc->tc_init1, i1, dlen); tc->tc_init1_len = dlen; assert(pmsl <= sizeof(tc->tc_pms)); memcpy(tc->tc_pms, pms, pmsl); tc->tc_pms_len = pmsl; assert(nonce_len <= sizeof(tc->tc_nonce)); memcpy(tc->tc_nonce, nonce, nonce_len); tc->tc_nonce_len = nonce_len; tc->tc_state = STATE_INIT1_RCVD; return 1; } static int swallow_data(struct ip *ip, struct tcphdr *tcp) { int len, dlen; len = (ip->ip_hl << 2) + (tcp->th_off << 2); dlen = ntohs(ip->ip_len) - len; set_ip_len(ip, len); return dlen; } static int do_input_pkconf_sent(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tc_subopt *tcs; int len, dlen; void *buf; struct ip *ip2; struct tcphdr *tcp2; struct tc_init2 *i2; uint8_t kxs[1024]; int cipherlen; /* syn retransmission */ if (tcp->th_flags == TH_SYN) return do_input_closed(tc, ip, tcp); if (!process_init1(tc, ip, tcp, kxs, sizeof(kxs))) { tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } cipherlen = tc->tc_crypt_pub->cp_cipher_len; /* send init2 */ buf = alloc_retransmit(tc); make_reply(buf, ip, tcp); ip2 = (struct ip*) buf; tcp2 = (struct tcphdr*) (ip2 + 1); tcs = subopt_alloc(tc, ip2, tcp2, 1); assert(tcs); tcs->tcs_op = TCOP_INIT2; len = sizeof(*i2) + cipherlen; i2 = data_alloc(tc, ip2, tcp2, len, 0); i2->i2_magic = htonl(TC_INIT2); i2->i2_len = htonl(len); i2->i2_scipher = tc->tc_cipher_sym; memcpy(i2->i2_data, kxs, cipherlen); if (_conf.cf_rsa_client_hack) memcpy(i2->i2_data, tc->tc_nonce, tc->tc_nonce_len); assert(len <= sizeof(tc->tc_init2)); memcpy(tc->tc_init2, i2, len); tc->tc_init2_len = len; checksum_packet(tc, ip2, tcp2); divert_inject(ip2, ntohs(ip2->ip_len)); tc->tc_state = STATE_INIT2_SENT; /* swallow data - ewwww */ dlen = swallow_data(ip, tcp); tc->tc_rseq_off = dlen; tc->tc_role = ROLE_SERVER; compute_ss(tc); #if 1 return DIVERT_MODIFY; #else /* we let the ACK of INIT2 through to complete the handshake */ return DIVERT_DROP; #endif } static int select_sym(struct tc *tc, struct tc_scipher *s) { struct tc_scipher *me = tc->tc_ciphers_sym; int len = tc->tc_ciphers_sym_len; int sym = 0; struct ciphers *c; /* check if we approve it */ while (len) { if (memcmp(me, s, sizeof(*s)) == 0) { sym = 1; break; } me++; len -= sizeof(*me); assert(len >= 0); } if (!sym) return 0; /* select ciphers */ c = _ciphers_sym.c_next; while (c) { me = (struct tc_scipher*) c->c_spec; if (me->sc_algo == s->sc_algo) { tc->tc_crypt_sym = crypt_new(c->c_cipher->c_ctr); break; } c = c->c_next; } assert(tc->tc_crypt_sym); memcpy(&tc->tc_cipher_sym, s, sizeof(*s)); return 1; } static int process_init2(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tc_subopt *tcs; struct tc_init2 *i2; int len; int nlen; void *nonce; void *key; int klen; uint8_t kxs[1024]; int kxs_len; tcs = find_subopt(tcp, TCOP_INIT2); if (!tcs) return bad_packet("init2: can't find opt"); i2 = tcp_data(tcp); len = tcp_data_len(ip, tcp); if (len < sizeof(*i2)) return bad_packet("init2: short packet"); if (len != ntohl(i2->i2_len)) return bad_packet("init2: bad lenn"); nlen = len - sizeof(*i2); if (nlen <= 0) return bad_packet("init2: bad len"); if (ntohl(i2->i2_magic) != TC_INIT2) return bad_packet("init2: bad magic"); if (!select_sym(tc, &i2->i2_scipher)) return bad_packet("init2: select_sym()"); if (nlen > sizeof(kxs)) return bad_packet("init2: big nonce kxs"); assert(len <= sizeof(tc->tc_init2)); memcpy(tc->tc_init2, i2, len); tc->tc_init2_len = len; /* XXX fix crypto api to use to / from */ kxs_len = nlen; memcpy(kxs, i2->i2_data, nlen); nonce = i2->i2_data; nlen = crypt_decrypt(tc->tc_crypt_pub->cp_pub, NULL, nonce, nlen); klen = crypt_get_key(tc->tc_crypt_pub->cp_pub, &key); assert(nlen <= sizeof(tc->tc_pms)); memcpy(tc->tc_pms, nonce, nlen); tc->tc_pms_len = nlen; compute_ss(tc); return 1; } static void ack(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { char buf[2048]; struct ip *ip2; struct tcphdr *tcp2; ip2 = (struct ip*) buf; tcp2 = (struct tcphdr*) (ip2 + 1); make_reply(buf, ip, tcp); /* XXX */ tcp2->th_seq = htonl(ntohl(tcp2->th_seq) - tc->tc_seq_off); tcp2->th_ack = htonl(ntohl(tcp2->th_ack) - tc->tc_rseq_off); checksum_packet(tc, ip2, tcp2); divert_inject(ip2, ntohs(ip2->ip_len)); } static int do_input_init1_sent(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int dlen; /* XXX syn ack re-TX - check pkconf */ if (tcp->th_flags == (TH_SYN | TH_ACK)) return DIVERT_ACCEPT; if (!process_init2(tc, ip, tcp)) { tc->tc_state = STATE_DISABLED; return DIVERT_ACCEPT; } dlen = ntohs(ip->ip_len) - (ip->ip_hl << 2) - (tcp->th_off << 2); tc->tc_rseq_off = dlen; ack(tc, ip, tcp); enable_encryption(tc); /* we let this packet through to reopen window */ swallow_data(ip, tcp); tcp->th_ack = htonl(ntohl(tcp->th_ack) - tc->tc_seq_off); return DIVERT_MODIFY; } static int check_mac(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tcpopt_mac *tom; void *mac = alloca(tc->tc_mac_size); assert(mac); tom = find_opt(tcp, TCPOPT_MAC); if (!tom) { if (!tc->tc_mac_rst && (tcp->th_flags & TH_RST)) return 0; return -1; } compute_mac(tc, ip, tcp, tc->tc_mac_ivlen ? tom->tom_data : NULL, mac, 1); if (memcmp(&tom->tom_data[tc->tc_mac_ivlen], mac, tc->tc_mac_size) != 0) return -2; return 0; } static int decrypt(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { uint8_t *data = tcp_data(tcp); int dlen = tcp_data_len(ip, tcp); void *iv = NULL; struct crypt *c = tc->tc_key_active->tc_alg_rx->cs_cipher; iv = get_iv(tc, ip, tcp); if (dlen) crypt_decrypt(c, iv, data, dlen); return dlen; } static struct tco_rekeystream *rekey_input(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tco_rekeystream *tr; /* half way through rekey - figure out current key */ if (tc->tc_keygentx != tc->tc_keygenrx && tc->tc_keygenrx == tc->tc_keygen) tc->tc_key_active = &tc->tc_key_next; tr = (struct tco_rekeystream *) find_subopt(tcp, TCOP_REKEY); if (!tr) return NULL; if (tr->tr_key == (uint8_t) ((tc->tc_keygen + 1))) { do_rekey(tc); tc->tc_state = STATE_REKEY_RCVD; tc->tc_rekey_seq = ntohl(tr->tr_seq); if (tc->tc_rekey_seq != ntohl(tcp->th_seq)) { assert(!"implement"); // unsigned char dummy[] = "a"; // void *iv = &tr->tr_seq; /* XXX assuming stream, and seq as IV */ // crypto_decrypt(tc, iv, dummy, sizeof(dummy)); } /* XXX assert that MAC checks out, else revert */ } assert(tr->tr_key == tc->tc_keygen); if (tr->tr_key == tc->tc_keygen) { /* old news - we've finished rekeying */ if (tc->tc_state == STATE_ENCRYPTING) { assert(tc->tc_keygen == tc->tc_keygenrx && tc->tc_keygen == tc->tc_keygentx); return NULL; } tc->tc_key_active = &tc->tc_key_next; } return tr; } static void rekey_input_post(struct tc *tc, struct ip *ip, struct tcphdr *tcp, struct tco_rekeystream *tr) { /* XXX seqno wrap */ if (tc->tc_state == STATE_REKEY_SENT && ntohl(tcp->th_ack) >= tc->tc_rekey_seq) { xprintf(XP_DEBUG, "TX rekey done %d %p\n", tc->tc_keygen, tc); tc->tc_keygentx++; assert(tc->tc_keygentx == tc->tc_keygen); if (rekey_complete(tc)) return; tc->tc_state = STATE_ENCRYPTING; } if (tr && (tc->tc_state = STATE_ENCRYPTING)) { tc->tc_state = STATE_REKEY_RCVD; tc->tc_rekey_seq = ntohl(tr->tr_seq); } } static int do_input_encrypting(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int rc; int v = DIVERT_ACCEPT; struct tco_rekeystream *tr; tc->tc_key_active = &tc->tc_key_current; tr = rekey_input(tc, ip, tcp); profile_add(1, "do_input pre check_mac"); if ((rc = check_mac(tc, ip, tcp))) { /* XXX gross */ if (rc == -1) { /* session caching */ if (tcp->th_flags == (TH_SYN | TH_ACK)) return DIVERT_ACCEPT; /* pkey */ else if (find_subopt(tcp, TCOP_INIT2)) { ack(tc, ip, tcp); return DIVERT_DROP; } } xprintf(XP_ALWAYS, "MAC failed %d\n", rc); if (_conf.cf_debug) abort(); return DIVERT_DROP; } else if (tc->tc_sess) { /* When we receive the first MACed packet, we know the other * side is setup so we can cache this session. */ tc->tc_sess->ts_used = 0; tc->tc_sess = NULL; } profile_add(1, "do_input post check_mac"); if (decrypt(tc, ip, tcp)) v = DIVERT_MODIFY; profile_add(1, "do_input post decrypt"); rekey_input_post(tc, ip, tcp, tr); if (fixup_seq(tc, tcp, 1)) v = DIVERT_MODIFY; return v; } static int do_input_init2_sent(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int rc; if (tc->tc_retransmit) { assert(find_subopt(tcp, TCOP_INIT1)); return DIVERT_DROP; } /* XXX check ACK */ enable_encryption(tc); rc = do_input_encrypting(tc, ip, tcp); assert(rc != DIVERT_DROP); return rc; } static int clamp_mss(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct { uint8_t kind; uint8_t len; uint16_t mss; } *mss; if (tc->tc_mss_clamp == -1) return DIVERT_ACCEPT; if (!(tcp->th_flags & TH_SYN)) return DIVERT_ACCEPT; if (tc->tc_state == STATE_DISABLED) return DIVERT_ACCEPT; mss = find_opt(tcp, TCPOPT_MAXSEG); if (!mss) { mss = tcp_opts_alloc(tc, ip, tcp, sizeof(*mss)); if (!mss) { tc->tc_state = STATE_DISABLED; xprintf(XP_ALWAYS, "Can't clamp MSS\n"); return DIVERT_ACCEPT; } mss->kind = TCPOPT_MAXSEG; mss->len = sizeof(*mss); mss->mss = htons(tc->tc_mtu - sizeof(*ip) - sizeof(*tcp)); } return do_clamp_mss(tc, &mss->mss); } static void check_retransmit(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct ip *ip2; struct tcphdr *tcp2; int seq; if (!tc->tc_retransmit) return; if (!(tcp->th_flags & TH_ACK)) return; ip2 = (struct ip*) tc->tc_retransmit->r_packet; tcp2 = (struct tcphdr*) ((unsigned long) ip2 + (ip2->ip_hl << 2)); seq = ntohl(tcp2->th_seq) + tcp_data_len(ip2, tcp2); if (ntohl(tcp->th_ack) < seq) return; kill_retransmit(tc); } static int tcp_input_pre(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int rc = DIVERT_ACCEPT; if (tcp->th_flags & TH_SYN) tc->tc_isn_peer = ntohl(tcp->th_seq); if (tcp->th_flags == TH_SYN && tc->tc_tcp_state == TCPSTATE_LASTACK) { tc_finish(tc); tc_reset(tc); } /* XXX check seq numbers, etc. */ check_retransmit(tc, ip, tcp); if (tcp->th_flags & TH_RST) { tc->tc_tcp_state = TCPSTATE_DEAD; return rc; } return rc; } static int tcp_input_post(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int rc = DIVERT_ACCEPT; if (clamp_mss(tc, ip, tcp) == DIVERT_MODIFY) rc = DIVERT_MODIFY; profile_add(2, "did clamp MSS"); /* Make sure kernel doesn't send shit until we connect */ switch (tc->tc_state) { case STATE_ENCRYPTING: case STATE_REKEY_SENT: case STATE_REKEY_RCVD: case STATE_DISABLED: case STATE_INIT2_SENT: break; default: tcp->th_win = htons(0); rc = DIVERT_MODIFY; break; } if (tcp->th_flags & TH_FIN) { switch (tc->tc_tcp_state) { case TCPSTATE_FIN1_SENT: tc->tc_tcp_state = TCPSTATE_FIN2_RCVD; break; case TCPSTATE_LASTACK: case TCPSTATE_FIN2_RCVD: break; default: tc->tc_tcp_state = TCPSTATE_FIN1_RCVD; break; } return rc; } if (tcp->th_flags & TH_RST) { tc->tc_tcp_state = TCPSTATE_DEAD; return rc; } switch (tc->tc_tcp_state) { case TCPSTATE_FIN2_SENT: if (tcp->th_flags & TH_ACK) tc->tc_tcp_state = TCPSTATE_DEAD; break; } return rc; } static int do_input_nextk1_sent(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { struct tc_subopt *sub; if (find_subopt(tcp, TCOP_NEXTK2_SUPPORT)) tc->tc_app_support |= 2; else { sub = find_subopt(tcp, TCOP_NEXTK2); if (!sub) { assert(tc->tc_sess->ts_used); tc->tc_sess->ts_used = 0; tc->tc_sess = NULL; if (!_conf.cf_nocache) xprintf(XP_DEFAULT, "Session caching failed\n"); return do_input_hello_sent(tc, ip, tcp); } } enable_encryption(tc); return DIVERT_ACCEPT; } static int do_input_nextk2_sent(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int rc; if (tcp->th_flags & TH_SYN) return DIVERT_ACCEPT; assert(tcp->th_flags & TH_ACK); enable_encryption(tc); rc = do_input_encrypting(tc, ip, tcp); assert(rc != DIVERT_DROP); return rc; } static int do_input(struct tc *tc, struct ip *ip, struct tcphdr *tcp) { int rc = DIVERT_DROP; int tcp_rc, tcp_rc2; tcp_rc = tcp_input_pre(tc, ip, tcp); /* an RST half way through the handshake */ if (tc->tc_tcp_state == TCPSTATE_DEAD && !connected(tc)) return tcp_rc; if (tcp_rc == DIVERT_DROP) return DIVERT_ACCEPT; /* kernel will deal with it */ switch (tc->tc_state) { case STATE_NEXTK1_RCVD: /* XXX check same SID */ case STATE_HELLO_RCVD: tc_reset(tc); /* XXX */ case STATE_CLOSED: rc = do_input_closed(tc, ip, tcp); break; case STATE_HELLO_SENT: rc = do_input_hello_sent(tc, ip, tcp); break; case STATE_PKCONF_RCVD: /* XXX syn ack re-TX check that we're getting the same shit */ assert(tcp->th_flags == (TH_SYN | TH_ACK)); rc = DIVERT_ACCEPT; break; case STATE_NEXTK1_SENT: rc = do_input_nextk1_sent(tc, ip, tcp); break; case STATE_NEXTK2_SENT: rc = do_input_nextk2_sent(tc, ip, tcp); break; case STATE_PKCONF_SENT: rc = do_input_pkconf_sent(tc, ip, tcp); break; case STATE_INIT1_SENT: rc = do_input_init1_sent(tc, ip, tcp); break; case STATE_INIT2_SENT: rc = do_input_init2_sent(tc, ip, tcp); break; case STATE_ENCRYPTING: case STATE_REKEY_SENT: case STATE_REKEY_RCVD: rc = do_input_encrypting(tc, ip, tcp); break; case STATE_DISABLED: rc = DIVERT_ACCEPT; break; default: xprintf(XP_ALWAYS, "Unknown state %d\n", tc->tc_state); abort(); } tcp_rc2 = tcp_input_post(tc, ip, tcp); if (tcp_rc == DIVERT_ACCEPT) tcp_rc = tcp_rc2; if (rc == DIVERT_ACCEPT) return tcp_rc; return rc; } int tcpcrypt_packet(void *packet, int len, int flags) { struct ip *ip = packet; struct tc *tc; struct tcphdr *tcp; int rc; profile_add(1, "tcpcrypt_packet in"); if (ntohs(ip->ip_len) != len) goto __bad_packet; if (ip->ip_p != IPPROTO_TCP) return DIVERT_ACCEPT; tcp = (struct tcphdr*) ((unsigned long) ip + (ip->ip_hl << 2)); if ((unsigned long) tcp - (unsigned long) ip + (tcp->th_off << 2) > len) goto __bad_packet; tc = lookup_connection(ip, tcp, flags); /* new connection */ if (!tc) { profile_add(1, "tcpcrypt_packet found no connection"); if (_conf.cf_disable) return DIVERT_ACCEPT; if (tcp->th_flags != TH_SYN) { xprintf(XP_NOISY, "Ignoring established connection: "); print_packet(ip, tcp, flags, tc); return DIVERT_ACCEPT; } tc = new_connection(ip, tcp, flags); profile_add(1, "tcpcrypt_packet new connection"); } else profile_add(1, "tcpcrypt_packet found connection"); print_packet(ip, tcp, flags, tc); tc->tc_dir_packet = (flags & DF_IN) ? DIR_IN : DIR_OUT; tc->tc_csum = 0; if (flags & DF_IN) rc = do_input(tc, ip, tcp); else rc = do_output(tc, ip, tcp); /* XXX for performance measuring - ensure sane results */ assert(!_conf.cf_debug || (tc->tc_state != STATE_DISABLED)); profile_add(1, "tcpcrypt_packet did processing"); if (rc == DIVERT_MODIFY) { checksum_tcp(tc, ip, tcp); profile_add(1, "tcpcrypt_packet did checksum"); } if (tc->tc_tcp_state == TCPSTATE_DEAD || tc->tc_state == STATE_DISABLED) remove_connection(ip, tcp, flags); profile_print(); return rc; __bad_packet: xprintf(XP_ALWAYS, "Bad packet\n"); return DIVERT_ACCEPT; /* kernel will drop / deal with it */ } static struct tc *sockopt_get(struct tcpcrypt_ctl *ctl) { struct tc *tc = sockopt_find(ctl); if (tc) return tc; if (ctl->tcc_sport == 0) return NULL; tc = get_tc(); assert(tc); _sockopts[ctl->tcc_sport] = tc; tc_init(tc); return tc; } static int do_opt(int set, void *p, int len, void *val, unsigned int *vallen) { if (set) { if (*vallen > len) return -1; memcpy(p, val, *vallen); return 0; } /* get */ if (len > *vallen) len = *vallen; memcpy(val, p, len); *vallen = len; return 0; } static int do_sockopt(int set, struct tc *tc, int opt, void *val, unsigned int *len) { int v; int rc; /* do not allow options during connection */ switch (tc->tc_state) { case STATE_CLOSED: case STATE_ENCRYPTING: case STATE_DISABLED: case STATE_REKEY_SENT: case STATE_REKEY_RCVD: break; default: return EBUSY; } switch (opt) { case TCP_CRYPT_ENABLE: if (tc->tc_state == STATE_DISABLED) v = 0; else v = 1; rc = do_opt(set, &v, sizeof(v), val, len); if (rc) return rc; /* XXX can't re-enable */ if (tc->tc_state == STATE_CLOSED && !v) tc->tc_state = STATE_DISABLED; break; case TCP_CRYPT_APP_SUPPORT: if (set) { if (tc->tc_state != STATE_CLOSED) return -1; return do_opt(set, &tc->tc_app_support, sizeof(tc->tc_app_support), val, len); } else { unsigned char *p = val; if (!connected(tc)) return -1; if (*len < (tc->tc_sid.s_len + 1)) return -1; *p++ = (char) tc->tc_app_support; memcpy(p, tc->tc_sid.s_data, tc->tc_sid.s_len); *len = tc->tc_sid.s_len + 1; return 0; } case TCP_CRYPT_NOCACHE: if (tc->tc_state != STATE_CLOSED) return -1; return do_opt(set, &tc->tc_nocache, sizeof(tc->tc_nocache), val, len); case TCP_CRYPT_CMODE: if (tc->tc_state != STATE_CLOSED) return -1; switch (tc->tc_cmode) { case CMODE_ALWAYS: case CMODE_ALWAYS_NK: v = 1; break; default: v = 0; break; } rc = do_opt(set, &v, sizeof(v), val, len); if (rc) return rc; if (!set) break; if (v) tc->tc_cmode = CMODE_ALWAYS; else tc->tc_cmode = CMODE_DEFAULT; break; case TCP_CRYPT_SESSID: if (set) return -1; if (!connected(tc)) return -1; return do_opt(set, tc->tc_sid.s_data, tc->tc_sid.s_len, val, len); default: return -1; } return 0; } int tcpcryptd_setsockopt(struct tcpcrypt_ctl *s, int opt, void *val, unsigned int len) { struct tc *tc; switch (opt) { case TCP_CRYPT_RESET: tc = sockopt_find(s); if (!tc) return -1; tc_finish(tc); put_tc(tc); sockopt_clear(s->tcc_sport); return 0; } tc = sockopt_get(s); if (!tc) return -1; return do_sockopt(1, tc, opt, val, &len); } static int do_tcpcrypt_netstat(struct conn *c, void *val, unsigned int *len) { struct tc_netstat *n = val; int l = *len; int copied = 0; struct tc *tc; int tl; while (c) { tc = c->c_tc; if (!connected(tc)) goto __next; if (tc->tc_tcp_state == TCPSTATE_LASTACK) goto __next; tl = sizeof(*n) + tc->tc_sid.s_len; if (l < tl) break; n->tn_sip.s_addr = c->c_addr[0].sin_addr.s_addr; n->tn_dip.s_addr = c->c_addr[1].sin_addr.s_addr; n->tn_sport = c->c_addr[0].sin_port; n->tn_dport = c->c_addr[1].sin_port; n->tn_len = htons(tc->tc_sid.s_len); memcpy(n->tn_sid, tc->tc_sid.s_data, tc->tc_sid.s_len); n = (struct tc_netstat*) ((unsigned long) n + tl); copied += tl; l -= tl; __next: c = c->c_next; } *len -= copied; return copied; } /* XXX slow */ static int tcpcrypt_netstat(void *val, unsigned int *len) { int i; int num = sizeof(_connection_map) / sizeof(*_connection_map); struct conn *c; int copied = 0; unsigned char *v = val; for (i = 0; i < num; i++) { c = _connection_map[i]; if (!c) continue; copied += do_tcpcrypt_netstat(c->c_next, &v[copied], len); } *len = copied; return 0; } int tcpcryptd_getsockopt(struct tcpcrypt_ctl *s, int opt, void *val, unsigned int *len) { struct tc *tc; switch (opt) { case TCP_CRYPT_NETSTAT: return tcpcrypt_netstat(val, len); } tc = sockopt_get(s); if (!tc) return -1; return do_sockopt(0, tc, opt, val, len); } static int get_pref(struct crypt_ops *ops) { int pref = 0; /* XXX implement */ return pref; } static void do_register_cipher(struct ciphers *c, struct cipher_list *cl) { struct ciphers *x; int pref = 0; x = xmalloc(sizeof(*x)); memset(x, 0, sizeof(*x)); x->c_cipher = cl; while (c->c_next) { if (pref >= get_pref(NULL)) break; c = c->c_next; } x->c_next = c->c_next; c->c_next = x; } void tcpcrypt_register_cipher(struct cipher_list *c) { int type = c->c_type; switch (type) { case TYPE_PKEY: do_register_cipher(&_ciphers_pkey, c); break; case TYPE_SYM: do_register_cipher(&_ciphers_sym, c); break; default: assert(!"Unknown type"); break; } } static void init_cipher(struct ciphers *c) { struct crypt_pub *cp; struct crypt_sym *cs; unsigned int spec = htonl(c->c_cipher->c_id); switch (c->c_cipher->c_type) { case TYPE_PKEY: c->c_speclen = 3; cp = c->c_cipher->c_ctr(); crypt_pub_destroy(cp); break; case TYPE_SYM: c->c_speclen = 4; cs = crypt_new(c->c_cipher->c_ctr); crypt_sym_destroy(cs); break; default: assert(!"unknown type"); abort(); } memcpy(c->c_spec, ((unsigned char*) &spec) + sizeof(spec) - c->c_speclen, c->c_speclen); } static void do_init_ciphers(struct ciphers *c) { struct tc *tc = get_tc(); struct ciphers *prev = c; struct ciphers *head = c; c = c->c_next; while (c) { /* XXX */ if (TC_DUMMY != TC_DUMMY) { if (!_conf.cf_dummy) { /* kill dummy */ prev->c_next = c->c_next; free(c); c = prev->c_next; continue; } else { /* leave all but dummy */ head->c_next = c; c->c_next = NULL; return; } } else if (!_conf.cf_dummy) { /* standard path */ init_cipher(c); } prev = c; c = c->c_next; } put_tc(tc); } static void init_ciphers(void) { do_init_ciphers(&_ciphers_pkey); do_init_ciphers(&_ciphers_sym); do_add_ciphers(&_ciphers_pkey, &_pkey, &_pkey_len, sizeof(*_pkey), (uint8_t*) _pkey + sizeof(_pkey)); do_add_ciphers(&_ciphers_sym, &_sym, &_sym_len, sizeof(*_sym), (uint8_t*) _sym + sizeof(_sym)); } void tcpcrypt_init(void) { srand(time(NULL)); /* XXX */ init_ciphers(); }
minnonymous/tcpcrypt
user/src/crypto.h
#ifndef __TCPCRYPT_CRYPTO_H__ #define __TCPCRYPT_CRYPTO_H__ typedef void *(*crypt_ctr)(void); enum { TYPE_PKEY = 0, TYPE_SYM, }; struct cipher_list { unsigned int c_id; int c_type; crypt_ctr c_ctr; struct cipher_list *c_next; }; extern struct cipher_list *crypt_cipher_list(void); /* low-level interface */ struct crypt { void *c_priv; void (*c_destroy)(struct crypt *c); int (*c_set_key)(struct crypt *c, void *key, int len); int (*c_get_key)(struct crypt *c, void **out); void (*c_mac)(struct crypt *, struct iovec *iov, int num, void *out, int *outlen); void (*c_extract)(struct crypt *c, struct iovec *iov, int num, void *out, int *outlen); void (*c_expand)(struct crypt *c, void *tag, int taglen, void *out, int outlen); int (*c_encrypt)(struct crypt *c, void *iv, void *data, int len); int (*c_decrypt)(struct crypt *c, void *iv, void *data, int len); int (*c_compute_key)(struct crypt *c, void *out); }; extern struct crypt *crypt_HMAC_SHA256_new(void); extern struct crypt *crypt_HKDF_SHA256_new(void); extern struct crypt *crypt_AES_new(void); extern struct crypt *crypt_RSA_new(void); extern struct crypt *crypt_ECDHE256_new(void); extern struct crypt *crypt_ECDHE521_new(void); extern struct crypt *crypt_init(int sz); extern void crypt_register(int type, unsigned int id, crypt_ctr ctr); extern struct cipher_list *crypt_find_cipher(int type, unsigned int id); static inline void crypt_destroy(struct crypt *c) { c->c_destroy(c); } static inline int crypt_set_key(struct crypt *c, void *key, int len) { return c->c_set_key(c, key, len); } static inline int crypt_get_key(struct crypt *c, void **out) { return c->c_get_key(c, out); } static inline void crypt_mac(struct crypt *c, struct iovec *iov, int num, void *out, int *outlen) { c->c_mac(c, iov, num, out, outlen); } static inline void *crypt_priv(struct crypt *c) { return c->c_priv; } static inline void crypt_extract(struct crypt *c, struct iovec *iov, int num, void *out, int *outlen) { c->c_extract(c, iov, num, out, outlen); } static inline void crypt_expand(struct crypt *c, void *tag, int taglen, void *out, int outlen) { c->c_expand(c, tag, taglen, out, outlen); } static inline int crypt_encrypt(struct crypt *c, void *iv, void *data, int len) { return c->c_encrypt(c, iv, data, len); } static inline int crypt_decrypt(struct crypt *c, void *iv, void *data, int len) { return c->c_decrypt(c, iv, data, len); } static inline int crypt_compute_key(struct crypt *c, void *out) { return c->c_compute_key(c, out); } static inline void *crypt_new(crypt_ctr ctr) { crypt_ctr *r = ctr(); *r = ctr; return r; } /* pub crypto */ struct crypt_pub { crypt_ctr cp_ctr; /* must be first */ struct crypt *cp_hkdf; struct crypt *cp_pub; int cp_n_c; int cp_n_s; int cp_k_len; int cp_min_key; int cp_max_key; int cp_cipher_len; int cp_key_agreement; }; static inline void crypt_pub_destroy(struct crypt_pub *cp) { crypt_destroy(cp->cp_hkdf); crypt_destroy(cp->cp_pub); free(cp); } /* sym crypto */ struct crypt_sym { crypt_ctr cs_ctr; /* must be first */ struct crypt *cs_cipher; struct crypt *cs_mac; struct crypt *cs_ack_mac; int cs_mac_len; int cs_iv_len; }; static inline void crypt_sym_destroy(struct crypt_sym *cs) { crypt_destroy(cs->cs_cipher); crypt_destroy(cs->cs_mac); crypt_destroy(cs->cs_ack_mac); free(cs); } #endif /* __TCPCRYPT_CRYPTO_H__ */
minnonymous/tcpcrypt
user/src/freebsd.c
<gh_stars>100-1000 #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #include <stdlib.h> #include <string.h> #include <err.h> #include <unistd.h> #include "tcpcrypt_divert.h" #include "tcpcryptd.h" static int _s; static divert_cb _cb; int divert_open(int port, divert_cb cb) { struct sockaddr_in s_in; memset(&s_in, 0, sizeof(s_in)); s_in.sin_family = PF_INET; s_in.sin_port = htons(port); if ((_s = socket(PF_INET, SOCK_RAW, IPPROTO_DIVERT)) == -1) err(1, "socket()"); if (bind(_s, (struct sockaddr*) &s_in, sizeof(s_in)) == -1) err(1, "bind()"); _cb = cb; xprintf(XP_DEFAULT, "Divert packets using ipfw add divert %d\n", port); open_raw(); return _s; } void divert_close(void) { close(_s); } void divert_next_packet(int s) { unsigned char buf[2048]; struct sockaddr_in s_in; socklen_t len = sizeof(s_in); int rc; int verdict; int flags = 0; rc = recvfrom(_s, buf, sizeof(buf), 0, (struct sockaddr*) &s_in, &len); if (rc == -1) err(1, "recvfrom()"); if (rc == 0) errx(1, "EOF"); if (s_in.sin_addr.s_addr != INADDR_ANY) flags |= DF_IN; verdict = _cb(buf, rc, flags); switch (verdict) { case DIVERT_MODIFY: rc = ntohs(((struct ip*) buf)->ip_len); /* fallthrough */ case DIVERT_ACCEPT: flags = sendto(_s, buf, rc, 0, (struct sockaddr*) &s_in, len); if (flags == -1) err(1, "sendto()"); if (flags != rc) errx(1, "sent %d/%d", flags, rc); break; case DIVERT_DROP: break; default: abort(); break; } }
minnonymous/tcpcrypt
user/src/crypto_hmac.c
#include <stdint.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <openssl/hmac.h> #include "inc.h" #include "tcpcrypt_ctl.h" #include "tcpcrypt.h" #include "tcpcryptd.h" #include "crypto.h" #include "profile.h" #define MAC_SIZE 32 struct hmac_priv { HMAC_CTX hp_ctx; int hp_fresh; }; static void hmac_destroy(struct crypt *c) { struct hmac_priv *hp = crypt_priv(c); if (!hp) return; HMAC_cleanup(&hp->hp_ctx); free(hp); free(c); } static void hmac_mac(struct crypt *c, struct iovec *iov, int num, void *out, int *outlen) { struct hmac_priv *hp = crypt_priv(c); void *o = out; unsigned int olen = MAC_SIZE; profile_add(3, "hmac_mac in"); if (!hp->hp_fresh) HMAC_Init_ex(&hp->hp_ctx, NULL, 0, NULL, NULL); else hp->hp_fresh = 0; while (num--) { HMAC_Update(&hp->hp_ctx, iov->iov_base, iov->iov_len); profile_add(3, "hmac_mac update"); iov++; } if (*outlen < MAC_SIZE) o = alloca(MAC_SIZE); HMAC_Final(&hp->hp_ctx, o, &olen); profile_add(3, "hmac_mac final"); if (*outlen < MAC_SIZE) memcpy(out, o, *outlen); else *outlen = olen; } static int hmac_set_key(struct crypt *c, void *key, int len) { struct hmac_priv *hp = crypt_priv(c); HMAC_Init_ex(&hp->hp_ctx, key, len, NULL, NULL); hp->hp_fresh = 1; return 0; } struct crypt *crypt_HMAC_SHA256_new(void) { struct hmac_priv *hp; struct crypt *c; c = crypt_init(sizeof(*hp)); c->c_destroy = hmac_destroy; c->c_set_key = hmac_set_key; c->c_mac = hmac_mac; hp = crypt_priv(c); HMAC_CTX_init(&hp->hp_ctx); HMAC_Init_ex(&hp->hp_ctx, "a", 1, EVP_sha256(), NULL); return c; }
raindust/incubator-teaclave-sgx-sdk
samplecode/psi/GoogleMessages/Messages.pb.h
<filename>samplecode/psi/GoogleMessages/Messages.pb.h // Generated by the protocol buffer compiler. DO NOT EDIT! // source: Messages.proto #ifndef PROTOBUF_Messages_2eproto__INCLUDED #define PROTOBUF_Messages_2eproto__INCLUDED #include <string> #include <google/protobuf/stubs/common.h> #if GOOGLE_PROTOBUF_VERSION < 3000000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif #if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. #endif #include <google/protobuf/arena.h> #include <google/protobuf/arenastring.h> #include <google/protobuf/generated_message_util.h> #include <google/protobuf/metadata.h> #include <google/protobuf/message.h> #include <google/protobuf/repeated_field.h> #include <google/protobuf/extension_set.h> #include <google/protobuf/unknown_field_set.h> // @@protoc_insertion_point(includes) namespace Messages { // Internal implementation detail -- do not call these. void protobuf_AddDesc_Messages_2eproto(); void protobuf_AssignDesc_Messages_2eproto(); void protobuf_ShutdownFile_Messages_2eproto(); class AttestationMessage; class InitialMessage; class MessageMSG1; class MessageMSG2; class MessageMSG3; class MessageMsg0; class MessagePsiHashData; class MessagePsiHashDataFinished; class MessagePsiIntersect; class MessagePsiResult; class MessagePsiSalt; // =================================================================== class InitialMessage : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.InitialMessage) */ { public: InitialMessage(); virtual ~InitialMessage(); InitialMessage(const InitialMessage& from); inline InitialMessage& operator=(const InitialMessage& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const InitialMessage& default_instance(); void Swap(InitialMessage* other); // implements Message ---------------------------------------------- inline InitialMessage* New() const { return New(NULL); } InitialMessage* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const InitialMessage& from); void MergeFrom(const InitialMessage& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(InitialMessage* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // optional uint32 size = 2; bool has_size() const; void clear_size(); static const int kSizeFieldNumber = 2; ::google::protobuf::uint32 size() const; void set_size(::google::protobuf::uint32 value); // @@protoc_insertion_point(class_scope:Messages.InitialMessage) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_size(); inline void clear_has_size(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 size_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static InitialMessage* default_instance_; }; // ------------------------------------------------------------------- class MessageMsg0 : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.MessageMsg0) */ { public: MessageMsg0(); virtual ~MessageMsg0(); MessageMsg0(const MessageMsg0& from); inline MessageMsg0& operator=(const MessageMsg0& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const MessageMsg0& default_instance(); void Swap(MessageMsg0* other); // implements Message ---------------------------------------------- inline MessageMsg0* New() const { return New(NULL); } MessageMsg0* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const MessageMsg0& from); void MergeFrom(const MessageMsg0& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessageMsg0* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // required uint32 epid = 2; bool has_epid() const; void clear_epid(); static const int kEpidFieldNumber = 2; ::google::protobuf::uint32 epid() const; void set_epid(::google::protobuf::uint32 value); // optional uint32 status = 3; bool has_status() const; void clear_status(); static const int kStatusFieldNumber = 3; ::google::protobuf::uint32 status() const; void set_status(::google::protobuf::uint32 value); // @@protoc_insertion_point(class_scope:Messages.MessageMsg0) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_epid(); inline void clear_has_epid(); inline void set_has_status(); inline void clear_has_status(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 epid_; ::google::protobuf::uint32 status_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static MessageMsg0* default_instance_; }; // ------------------------------------------------------------------- class MessageMSG1 : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.MessageMSG1) */ { public: MessageMSG1(); virtual ~MessageMSG1(); MessageMSG1(const MessageMSG1& from); inline MessageMSG1& operator=(const MessageMSG1& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const MessageMSG1& default_instance(); void Swap(MessageMSG1* other); // implements Message ---------------------------------------------- inline MessageMSG1* New() const { return New(NULL); } MessageMSG1* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const MessageMSG1& from); void MergeFrom(const MessageMSG1& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessageMSG1* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // required uint32 context = 2; bool has_context() const; void clear_context(); static const int kContextFieldNumber = 2; ::google::protobuf::uint32 context() const; void set_context(::google::protobuf::uint32 value); // repeated uint32 GaX = 3 [packed = true]; int gax_size() const; void clear_gax(); static const int kGaXFieldNumber = 3; ::google::protobuf::uint32 gax(int index) const; void set_gax(int index, ::google::protobuf::uint32 value); void add_gax(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& gax() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_gax(); // repeated uint32 GaY = 4 [packed = true]; int gay_size() const; void clear_gay(); static const int kGaYFieldNumber = 4; ::google::protobuf::uint32 gay(int index) const; void set_gay(int index, ::google::protobuf::uint32 value); void add_gay(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& gay() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_gay(); // repeated uint32 GID = 5 [packed = true]; int gid_size() const; void clear_gid(); static const int kGIDFieldNumber = 5; ::google::protobuf::uint32 gid(int index) const; void set_gid(int index, ::google::protobuf::uint32 value); void add_gid(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& gid() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_gid(); // @@protoc_insertion_point(class_scope:Messages.MessageMSG1) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_context(); inline void clear_has_context(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 context_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > gax_; mutable int _gax_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > gay_; mutable int _gay_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > gid_; mutable int _gid_cached_byte_size_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static MessageMSG1* default_instance_; }; // ------------------------------------------------------------------- class MessageMSG2 : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.MessageMSG2) */ { public: MessageMSG2(); virtual ~MessageMSG2(); MessageMSG2(const MessageMSG2& from); inline MessageMSG2& operator=(const MessageMSG2& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const MessageMSG2& default_instance(); void Swap(MessageMSG2* other); // implements Message ---------------------------------------------- inline MessageMSG2* New() const { return New(NULL); } MessageMSG2* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const MessageMSG2& from); void MergeFrom(const MessageMSG2& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessageMSG2* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // optional uint32 size = 2; bool has_size() const; void clear_size(); static const int kSizeFieldNumber = 2; ::google::protobuf::uint32 size() const; void set_size(::google::protobuf::uint32 value); // required uint32 context = 3; bool has_context() const; void clear_context(); static const int kContextFieldNumber = 3; ::google::protobuf::uint32 context() const; void set_context(::google::protobuf::uint32 value); // repeated uint32 public_key_gx = 4 [packed = true]; int public_key_gx_size() const; void clear_public_key_gx(); static const int kPublicKeyGxFieldNumber = 4; ::google::protobuf::uint32 public_key_gx(int index) const; void set_public_key_gx(int index, ::google::protobuf::uint32 value); void add_public_key_gx(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& public_key_gx() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_public_key_gx(); // repeated uint32 public_key_gy = 5 [packed = true]; int public_key_gy_size() const; void clear_public_key_gy(); static const int kPublicKeyGyFieldNumber = 5; ::google::protobuf::uint32 public_key_gy(int index) const; void set_public_key_gy(int index, ::google::protobuf::uint32 value); void add_public_key_gy(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& public_key_gy() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_public_key_gy(); // optional uint32 quote_type = 6; bool has_quote_type() const; void clear_quote_type(); static const int kQuoteTypeFieldNumber = 6; ::google::protobuf::uint32 quote_type() const; void set_quote_type(::google::protobuf::uint32 value); // repeated uint32 spid = 7 [packed = true]; int spid_size() const; void clear_spid(); static const int kSpidFieldNumber = 7; ::google::protobuf::uint32 spid(int index) const; void set_spid(int index, ::google::protobuf::uint32 value); void add_spid(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& spid() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_spid(); // optional uint32 cmac_kdf_id = 8; bool has_cmac_kdf_id() const; void clear_cmac_kdf_id(); static const int kCmacKdfIdFieldNumber = 8; ::google::protobuf::uint32 cmac_kdf_id() const; void set_cmac_kdf_id(::google::protobuf::uint32 value); // repeated uint32 signature_x = 9 [packed = true]; int signature_x_size() const; void clear_signature_x(); static const int kSignatureXFieldNumber = 9; ::google::protobuf::uint32 signature_x(int index) const; void set_signature_x(int index, ::google::protobuf::uint32 value); void add_signature_x(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& signature_x() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_signature_x(); // repeated uint32 signature_y = 10 [packed = true]; int signature_y_size() const; void clear_signature_y(); static const int kSignatureYFieldNumber = 10; ::google::protobuf::uint32 signature_y(int index) const; void set_signature_y(int index, ::google::protobuf::uint32 value); void add_signature_y(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& signature_y() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_signature_y(); // repeated uint32 smac = 11 [packed = true]; int smac_size() const; void clear_smac(); static const int kSmacFieldNumber = 11; ::google::protobuf::uint32 smac(int index) const; void set_smac(int index, ::google::protobuf::uint32 value); void add_smac(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& smac() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_smac(); // optional uint32 size_sigrl = 12; bool has_size_sigrl() const; void clear_size_sigrl(); static const int kSizeSigrlFieldNumber = 12; ::google::protobuf::uint32 size_sigrl() const; void set_size_sigrl(::google::protobuf::uint32 value); // repeated uint32 sigrl = 13 [packed = true]; int sigrl_size() const; void clear_sigrl(); static const int kSigrlFieldNumber = 13; ::google::protobuf::uint32 sigrl(int index) const; void set_sigrl(int index, ::google::protobuf::uint32 value); void add_sigrl(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& sigrl() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_sigrl(); // @@protoc_insertion_point(class_scope:Messages.MessageMSG2) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_size(); inline void clear_has_size(); inline void set_has_context(); inline void clear_has_context(); inline void set_has_quote_type(); inline void clear_has_quote_type(); inline void set_has_cmac_kdf_id(); inline void clear_has_cmac_kdf_id(); inline void set_has_size_sigrl(); inline void clear_has_size_sigrl(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > public_key_gx_; mutable int _public_key_gx_cached_byte_size_; ::google::protobuf::uint32 context_; ::google::protobuf::uint32 quote_type_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > public_key_gy_; mutable int _public_key_gy_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > spid_; mutable int _spid_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > signature_x_; mutable int _signature_x_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > signature_y_; mutable int _signature_y_cached_byte_size_; ::google::protobuf::uint32 cmac_kdf_id_; ::google::protobuf::uint32 size_sigrl_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > smac_; mutable int _smac_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > sigrl_; mutable int _sigrl_cached_byte_size_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static MessageMSG2* default_instance_; }; // ------------------------------------------------------------------- class MessageMSG3 : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.MessageMSG3) */ { public: MessageMSG3(); virtual ~MessageMSG3(); MessageMSG3(const MessageMSG3& from); inline MessageMSG3& operator=(const MessageMSG3& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const MessageMSG3& default_instance(); void Swap(MessageMSG3* other); // implements Message ---------------------------------------------- inline MessageMSG3* New() const { return New(NULL); } MessageMSG3* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const MessageMSG3& from); void MergeFrom(const MessageMSG3& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessageMSG3* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // optional uint32 size = 2; bool has_size() const; void clear_size(); static const int kSizeFieldNumber = 2; ::google::protobuf::uint32 size() const; void set_size(::google::protobuf::uint32 value); // required uint32 context = 3; bool has_context() const; void clear_context(); static const int kContextFieldNumber = 3; ::google::protobuf::uint32 context() const; void set_context(::google::protobuf::uint32 value); // repeated uint32 sgx_mac = 4 [packed = true]; int sgx_mac_size() const; void clear_sgx_mac(); static const int kSgxMacFieldNumber = 4; ::google::protobuf::uint32 sgx_mac(int index) const; void set_sgx_mac(int index, ::google::protobuf::uint32 value); void add_sgx_mac(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& sgx_mac() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_sgx_mac(); // repeated uint32 gax_msg3 = 5 [packed = true]; int gax_msg3_size() const; void clear_gax_msg3(); static const int kGaxMsg3FieldNumber = 5; ::google::protobuf::uint32 gax_msg3(int index) const; void set_gax_msg3(int index, ::google::protobuf::uint32 value); void add_gax_msg3(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& gax_msg3() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_gax_msg3(); // repeated uint32 gay_msg3 = 6 [packed = true]; int gay_msg3_size() const; void clear_gay_msg3(); static const int kGayMsg3FieldNumber = 6; ::google::protobuf::uint32 gay_msg3(int index) const; void set_gay_msg3(int index, ::google::protobuf::uint32 value); void add_gay_msg3(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& gay_msg3() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_gay_msg3(); // repeated uint32 sec_property = 7 [packed = true]; int sec_property_size() const; void clear_sec_property(); static const int kSecPropertyFieldNumber = 7; ::google::protobuf::uint32 sec_property(int index) const; void set_sec_property(int index, ::google::protobuf::uint32 value); void add_sec_property(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& sec_property() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_sec_property(); // repeated uint32 quote = 8 [packed = true]; int quote_size() const; void clear_quote(); static const int kQuoteFieldNumber = 8; ::google::protobuf::uint32 quote(int index) const; void set_quote(int index, ::google::protobuf::uint32 value); void add_quote(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& quote() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_quote(); // @@protoc_insertion_point(class_scope:Messages.MessageMSG3) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_size(); inline void clear_has_size(); inline void set_has_context(); inline void clear_has_context(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > sgx_mac_; mutable int _sgx_mac_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > gax_msg3_; mutable int _gax_msg3_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > gay_msg3_; mutable int _gay_msg3_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > sec_property_; mutable int _sec_property_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > quote_; mutable int _quote_cached_byte_size_; ::google::protobuf::uint32 context_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static MessageMSG3* default_instance_; }; // ------------------------------------------------------------------- class AttestationMessage : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.AttestationMessage) */ { public: AttestationMessage(); virtual ~AttestationMessage(); AttestationMessage(const AttestationMessage& from); inline AttestationMessage& operator=(const AttestationMessage& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const AttestationMessage& default_instance(); void Swap(AttestationMessage* other); // implements Message ---------------------------------------------- inline AttestationMessage* New() const { return New(NULL); } AttestationMessage* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const AttestationMessage& from); void MergeFrom(const AttestationMessage& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(AttestationMessage* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // required uint32 size = 2; bool has_size() const; void clear_size(); static const int kSizeFieldNumber = 2; ::google::protobuf::uint32 size() const; void set_size(::google::protobuf::uint32 value); // required uint32 context = 3; bool has_context() const; void clear_context(); static const int kContextFieldNumber = 3; ::google::protobuf::uint32 context() const; void set_context(::google::protobuf::uint32 value); // optional uint32 epid_group_status = 4; bool has_epid_group_status() const; void clear_epid_group_status(); static const int kEpidGroupStatusFieldNumber = 4; ::google::protobuf::uint32 epid_group_status() const; void set_epid_group_status(::google::protobuf::uint32 value); // optional uint32 tcb_evaluation_status = 5; bool has_tcb_evaluation_status() const; void clear_tcb_evaluation_status(); static const int kTcbEvaluationStatusFieldNumber = 5; ::google::protobuf::uint32 tcb_evaluation_status() const; void set_tcb_evaluation_status(::google::protobuf::uint32 value); // optional uint32 pse_evaluation_status = 6; bool has_pse_evaluation_status() const; void clear_pse_evaluation_status(); static const int kPseEvaluationStatusFieldNumber = 6; ::google::protobuf::uint32 pse_evaluation_status() const; void set_pse_evaluation_status(::google::protobuf::uint32 value); // repeated uint32 latest_equivalent_tcb_psvn = 7 [packed = true]; int latest_equivalent_tcb_psvn_size() const; void clear_latest_equivalent_tcb_psvn(); static const int kLatestEquivalentTcbPsvnFieldNumber = 7; ::google::protobuf::uint32 latest_equivalent_tcb_psvn(int index) const; void set_latest_equivalent_tcb_psvn(int index, ::google::protobuf::uint32 value); void add_latest_equivalent_tcb_psvn(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& latest_equivalent_tcb_psvn() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_latest_equivalent_tcb_psvn(); // repeated uint32 latest_pse_isvsvn = 8 [packed = true]; int latest_pse_isvsvn_size() const; void clear_latest_pse_isvsvn(); static const int kLatestPseIsvsvnFieldNumber = 8; ::google::protobuf::uint32 latest_pse_isvsvn(int index) const; void set_latest_pse_isvsvn(int index, ::google::protobuf::uint32 value); void add_latest_pse_isvsvn(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& latest_pse_isvsvn() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_latest_pse_isvsvn(); // repeated uint32 latest_psda_svn = 9 [packed = true]; int latest_psda_svn_size() const; void clear_latest_psda_svn(); static const int kLatestPsdaSvnFieldNumber = 9; ::google::protobuf::uint32 latest_psda_svn(int index) const; void set_latest_psda_svn(int index, ::google::protobuf::uint32 value); void add_latest_psda_svn(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& latest_psda_svn() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_latest_psda_svn(); // repeated uint32 performance_rekey_gid = 10 [packed = true]; int performance_rekey_gid_size() const; void clear_performance_rekey_gid(); static const int kPerformanceRekeyGidFieldNumber = 10; ::google::protobuf::uint32 performance_rekey_gid(int index) const; void set_performance_rekey_gid(int index, ::google::protobuf::uint32 value); void add_performance_rekey_gid(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& performance_rekey_gid() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_performance_rekey_gid(); // repeated uint32 ec_sign256_x = 11 [packed = true]; int ec_sign256_x_size() const; void clear_ec_sign256_x(); static const int kEcSign256XFieldNumber = 11; ::google::protobuf::uint32 ec_sign256_x(int index) const; void set_ec_sign256_x(int index, ::google::protobuf::uint32 value); void add_ec_sign256_x(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& ec_sign256_x() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_ec_sign256_x(); // repeated uint32 ec_sign256_y = 12 [packed = true]; int ec_sign256_y_size() const; void clear_ec_sign256_y(); static const int kEcSign256YFieldNumber = 12; ::google::protobuf::uint32 ec_sign256_y(int index) const; void set_ec_sign256_y(int index, ::google::protobuf::uint32 value); void add_ec_sign256_y(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& ec_sign256_y() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_ec_sign256_y(); // repeated uint32 mac_smk = 13 [packed = true]; int mac_smk_size() const; void clear_mac_smk(); static const int kMacSmkFieldNumber = 13; ::google::protobuf::uint32 mac_smk(int index) const; void set_mac_smk(int index, ::google::protobuf::uint32 value); void add_mac_smk(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& mac_smk() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_mac_smk(); // optional uint32 result_size = 14; bool has_result_size() const; void clear_result_size(); static const int kResultSizeFieldNumber = 14; ::google::protobuf::uint32 result_size() const; void set_result_size(::google::protobuf::uint32 value); // repeated uint32 reserved = 15 [packed = true]; int reserved_size() const; void clear_reserved(); static const int kReservedFieldNumber = 15; ::google::protobuf::uint32 reserved(int index) const; void set_reserved(int index, ::google::protobuf::uint32 value); void add_reserved(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& reserved() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_reserved(); // repeated uint32 payload_tag = 16 [packed = true]; int payload_tag_size() const; void clear_payload_tag(); static const int kPayloadTagFieldNumber = 16; ::google::protobuf::uint32 payload_tag(int index) const; void set_payload_tag(int index, ::google::protobuf::uint32 value); void add_payload_tag(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& payload_tag() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_payload_tag(); // repeated uint32 payload = 17 [packed = true]; int payload_size() const; void clear_payload(); static const int kPayloadFieldNumber = 17; ::google::protobuf::uint32 payload(int index) const; void set_payload(int index, ::google::protobuf::uint32 value); void add_payload(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& payload() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_payload(); // @@protoc_insertion_point(class_scope:Messages.AttestationMessage) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_size(); inline void clear_has_size(); inline void set_has_context(); inline void clear_has_context(); inline void set_has_epid_group_status(); inline void clear_has_epid_group_status(); inline void set_has_tcb_evaluation_status(); inline void clear_has_tcb_evaluation_status(); inline void set_has_pse_evaluation_status(); inline void clear_has_pse_evaluation_status(); inline void set_has_result_size(); inline void clear_has_result_size(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 size_; ::google::protobuf::uint32 context_; ::google::protobuf::uint32 epid_group_status_; ::google::protobuf::uint32 tcb_evaluation_status_; ::google::protobuf::uint32 pse_evaluation_status_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > latest_equivalent_tcb_psvn_; mutable int _latest_equivalent_tcb_psvn_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > latest_pse_isvsvn_; mutable int _latest_pse_isvsvn_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > latest_psda_svn_; mutable int _latest_psda_svn_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > performance_rekey_gid_; mutable int _performance_rekey_gid_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > ec_sign256_x_; mutable int _ec_sign256_x_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > ec_sign256_y_; mutable int _ec_sign256_y_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > mac_smk_; mutable int _mac_smk_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > reserved_; mutable int _reserved_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > payload_tag_; mutable int _payload_tag_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > payload_; mutable int _payload_cached_byte_size_; ::google::protobuf::uint32 result_size_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static AttestationMessage* default_instance_; }; // ------------------------------------------------------------------- class MessagePsiSalt : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.MessagePsiSalt) */ { public: MessagePsiSalt(); virtual ~MessagePsiSalt(); MessagePsiSalt(const MessagePsiSalt& from); inline MessagePsiSalt& operator=(const MessagePsiSalt& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const MessagePsiSalt& default_instance(); void Swap(MessagePsiSalt* other); // implements Message ---------------------------------------------- inline MessagePsiSalt* New() const { return New(NULL); } MessagePsiSalt* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const MessagePsiSalt& from); void MergeFrom(const MessagePsiSalt& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessagePsiSalt* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // required uint32 size = 2; bool has_size() const; void clear_size(); static const int kSizeFieldNumber = 2; ::google::protobuf::uint32 size() const; void set_size(::google::protobuf::uint32 value); // required uint32 context = 3; bool has_context() const; void clear_context(); static const int kContextFieldNumber = 3; ::google::protobuf::uint32 context() const; void set_context(::google::protobuf::uint32 value); // required uint32 id = 4; bool has_id() const; void clear_id(); static const int kIdFieldNumber = 4; ::google::protobuf::uint32 id() const; void set_id(::google::protobuf::uint32 value); // required uint32 state = 5; bool has_state() const; void clear_state(); static const int kStateFieldNumber = 5; ::google::protobuf::uint32 state() const; void set_state(::google::protobuf::uint32 value); // repeated uint32 mac = 6 [packed = true]; int mac_size() const; void clear_mac(); static const int kMacFieldNumber = 6; ::google::protobuf::uint32 mac(int index) const; void set_mac(int index, ::google::protobuf::uint32 value); void add_mac(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& mac() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_mac(); // repeated uint32 salt = 7 [packed = true]; int salt_size() const; void clear_salt(); static const int kSaltFieldNumber = 7; ::google::protobuf::uint32 salt(int index) const; void set_salt(int index, ::google::protobuf::uint32 value); void add_salt(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& salt() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_salt(); // @@protoc_insertion_point(class_scope:Messages.MessagePsiSalt) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_size(); inline void clear_has_size(); inline void set_has_context(); inline void clear_has_context(); inline void set_has_id(); inline void clear_has_id(); inline void set_has_state(); inline void clear_has_state(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 size_; ::google::protobuf::uint32 context_; ::google::protobuf::uint32 id_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > mac_; mutable int _mac_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > salt_; mutable int _salt_cached_byte_size_; ::google::protobuf::uint32 state_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static MessagePsiSalt* default_instance_; }; // ------------------------------------------------------------------- class MessagePsiHashData : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.MessagePsiHashData) */ { public: MessagePsiHashData(); virtual ~MessagePsiHashData(); MessagePsiHashData(const MessagePsiHashData& from); inline MessagePsiHashData& operator=(const MessagePsiHashData& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const MessagePsiHashData& default_instance(); void Swap(MessagePsiHashData* other); // implements Message ---------------------------------------------- inline MessagePsiHashData* New() const { return New(NULL); } MessagePsiHashData* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const MessagePsiHashData& from); void MergeFrom(const MessagePsiHashData& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessagePsiHashData* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // required uint32 size = 2; bool has_size() const; void clear_size(); static const int kSizeFieldNumber = 2; ::google::protobuf::uint32 size() const; void set_size(::google::protobuf::uint32 value); // required uint32 context = 3; bool has_context() const; void clear_context(); static const int kContextFieldNumber = 3; ::google::protobuf::uint32 context() const; void set_context(::google::protobuf::uint32 value); // required uint32 id = 4; bool has_id() const; void clear_id(); static const int kIdFieldNumber = 4; ::google::protobuf::uint32 id() const; void set_id(::google::protobuf::uint32 value); // repeated uint32 mac = 5 [packed = true]; int mac_size() const; void clear_mac(); static const int kMacFieldNumber = 5; ::google::protobuf::uint32 mac(int index) const; void set_mac(int index, ::google::protobuf::uint32 value); void add_mac(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& mac() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_mac(); // repeated uint32 data = 6 [packed = true]; int data_size() const; void clear_data(); static const int kDataFieldNumber = 6; ::google::protobuf::uint32 data(int index) const; void set_data(int index, ::google::protobuf::uint32 value); void add_data(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& data() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_data(); // @@protoc_insertion_point(class_scope:Messages.MessagePsiHashData) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_size(); inline void clear_has_size(); inline void set_has_context(); inline void clear_has_context(); inline void set_has_id(); inline void clear_has_id(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 size_; ::google::protobuf::uint32 context_; ::google::protobuf::uint32 id_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > mac_; mutable int _mac_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > data_; mutable int _data_cached_byte_size_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static MessagePsiHashData* default_instance_; }; // ------------------------------------------------------------------- class MessagePsiHashDataFinished : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.MessagePsiHashDataFinished) */ { public: MessagePsiHashDataFinished(); virtual ~MessagePsiHashDataFinished(); MessagePsiHashDataFinished(const MessagePsiHashDataFinished& from); inline MessagePsiHashDataFinished& operator=(const MessagePsiHashDataFinished& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const MessagePsiHashDataFinished& default_instance(); void Swap(MessagePsiHashDataFinished* other); // implements Message ---------------------------------------------- inline MessagePsiHashDataFinished* New() const { return New(NULL); } MessagePsiHashDataFinished* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const MessagePsiHashDataFinished& from); void MergeFrom(const MessagePsiHashDataFinished& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessagePsiHashDataFinished* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // required uint32 size = 2; bool has_size() const; void clear_size(); static const int kSizeFieldNumber = 2; ::google::protobuf::uint32 size() const; void set_size(::google::protobuf::uint32 value); // required uint32 context = 3; bool has_context() const; void clear_context(); static const int kContextFieldNumber = 3; ::google::protobuf::uint32 context() const; void set_context(::google::protobuf::uint32 value); // required uint32 id = 4; bool has_id() const; void clear_id(); static const int kIdFieldNumber = 4; ::google::protobuf::uint32 id() const; void set_id(::google::protobuf::uint32 value); // @@protoc_insertion_point(class_scope:Messages.MessagePsiHashDataFinished) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_size(); inline void clear_has_size(); inline void set_has_context(); inline void clear_has_context(); inline void set_has_id(); inline void clear_has_id(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 size_; ::google::protobuf::uint32 context_; ::google::protobuf::uint32 id_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static MessagePsiHashDataFinished* default_instance_; }; // ------------------------------------------------------------------- class MessagePsiResult : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.MessagePsiResult) */ { public: MessagePsiResult(); virtual ~MessagePsiResult(); MessagePsiResult(const MessagePsiResult& from); inline MessagePsiResult& operator=(const MessagePsiResult& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const MessagePsiResult& default_instance(); void Swap(MessagePsiResult* other); // implements Message ---------------------------------------------- inline MessagePsiResult* New() const { return New(NULL); } MessagePsiResult* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const MessagePsiResult& from); void MergeFrom(const MessagePsiResult& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessagePsiResult* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // required uint32 size = 2; bool has_size() const; void clear_size(); static const int kSizeFieldNumber = 2; ::google::protobuf::uint32 size() const; void set_size(::google::protobuf::uint32 value); // required uint32 context = 3; bool has_context() const; void clear_context(); static const int kContextFieldNumber = 3; ::google::protobuf::uint32 context() const; void set_context(::google::protobuf::uint32 value); // required uint32 id = 4; bool has_id() const; void clear_id(); static const int kIdFieldNumber = 4; ::google::protobuf::uint32 id() const; void set_id(::google::protobuf::uint32 value); // required uint32 state = 5; bool has_state() const; void clear_state(); static const int kStateFieldNumber = 5; ::google::protobuf::uint32 state() const; void set_state(::google::protobuf::uint32 value); // @@protoc_insertion_point(class_scope:Messages.MessagePsiResult) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_size(); inline void clear_has_size(); inline void set_has_context(); inline void clear_has_context(); inline void set_has_id(); inline void clear_has_id(); inline void set_has_state(); inline void clear_has_state(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 size_; ::google::protobuf::uint32 context_; ::google::protobuf::uint32 id_; ::google::protobuf::uint32 state_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static MessagePsiResult* default_instance_; }; // ------------------------------------------------------------------- class MessagePsiIntersect : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Messages.MessagePsiIntersect) */ { public: MessagePsiIntersect(); virtual ~MessagePsiIntersect(); MessagePsiIntersect(const MessagePsiIntersect& from); inline MessagePsiIntersect& operator=(const MessagePsiIntersect& from) { CopyFrom(from); return *this; } inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const MessagePsiIntersect& default_instance(); void Swap(MessagePsiIntersect* other); // implements Message ---------------------------------------------- inline MessagePsiIntersect* New() const { return New(NULL); } MessagePsiIntersect* New(::google::protobuf::Arena* arena) const; void CopyFrom(const ::google::protobuf::Message& from); void MergeFrom(const ::google::protobuf::Message& from); void CopyFrom(const MessagePsiIntersect& from); void MergeFrom(const MessagePsiIntersect& from); void Clear(); bool IsInitialized() const; int ByteSize() const; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input); void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* output) const; ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { return InternalSerializeWithCachedSizesToArray(false, output); } int GetCachedSize() const { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const; void InternalSwap(MessagePsiIntersect* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return _internal_metadata_.arena(); } inline void* MaybeArenaPtr() const { return _internal_metadata_.raw_arena_ptr(); } public: ::google::protobuf::Metadata GetMetadata() const; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required uint32 type = 1; bool has_type() const; void clear_type(); static const int kTypeFieldNumber = 1; ::google::protobuf::uint32 type() const; void set_type(::google::protobuf::uint32 value); // required uint32 size = 2; bool has_size() const; void clear_size(); static const int kSizeFieldNumber = 2; ::google::protobuf::uint32 size() const; void set_size(::google::protobuf::uint32 value); // required uint32 context = 3; bool has_context() const; void clear_context(); static const int kContextFieldNumber = 3; ::google::protobuf::uint32 context() const; void set_context(::google::protobuf::uint32 value); // required uint32 id = 4; bool has_id() const; void clear_id(); static const int kIdFieldNumber = 4; ::google::protobuf::uint32 id() const; void set_id(::google::protobuf::uint32 value); // repeated uint32 mac = 5 [packed = true]; int mac_size() const; void clear_mac(); static const int kMacFieldNumber = 5; ::google::protobuf::uint32 mac(int index) const; void set_mac(int index, ::google::protobuf::uint32 value); void add_mac(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& mac() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_mac(); // repeated uint32 data = 6 [packed = true]; int data_size() const; void clear_data(); static const int kDataFieldNumber = 6; ::google::protobuf::uint32 data(int index) const; void set_data(int index, ::google::protobuf::uint32 value); void add_data(::google::protobuf::uint32 value); const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& data() const; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* mutable_data(); // @@protoc_insertion_point(class_scope:Messages.MessagePsiIntersect) private: inline void set_has_type(); inline void clear_has_type(); inline void set_has_size(); inline void clear_has_size(); inline void set_has_context(); inline void clear_has_context(); inline void set_has_id(); inline void clear_has_id(); // helper for ByteSize() int RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::uint32 _has_bits_[1]; mutable int _cached_size_; ::google::protobuf::uint32 type_; ::google::protobuf::uint32 size_; ::google::protobuf::uint32 context_; ::google::protobuf::uint32 id_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > mac_; mutable int _mac_cached_byte_size_; ::google::protobuf::RepeatedField< ::google::protobuf::uint32 > data_; mutable int _data_cached_byte_size_; friend void protobuf_AddDesc_Messages_2eproto(); friend void protobuf_AssignDesc_Messages_2eproto(); friend void protobuf_ShutdownFile_Messages_2eproto(); void InitAsDefaultInstance(); static MessagePsiIntersect* default_instance_; }; // =================================================================== // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS // InitialMessage // required uint32 type = 1; inline bool InitialMessage::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void InitialMessage::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void InitialMessage::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void InitialMessage::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 InitialMessage::type() const { // @@protoc_insertion_point(field_get:Messages.InitialMessage.type) return type_; } inline void InitialMessage::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.InitialMessage.type) } // optional uint32 size = 2; inline bool InitialMessage::has_size() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void InitialMessage::set_has_size() { _has_bits_[0] |= 0x00000002u; } inline void InitialMessage::clear_has_size() { _has_bits_[0] &= ~0x00000002u; } inline void InitialMessage::clear_size() { size_ = 0u; clear_has_size(); } inline ::google::protobuf::uint32 InitialMessage::size() const { // @@protoc_insertion_point(field_get:Messages.InitialMessage.size) return size_; } inline void InitialMessage::set_size(::google::protobuf::uint32 value) { set_has_size(); size_ = value; // @@protoc_insertion_point(field_set:Messages.InitialMessage.size) } // ------------------------------------------------------------------- // MessageMsg0 // required uint32 type = 1; inline bool MessageMsg0::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void MessageMsg0::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void MessageMsg0::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void MessageMsg0::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 MessageMsg0::type() const { // @@protoc_insertion_point(field_get:Messages.MessageMsg0.type) return type_; } inline void MessageMsg0::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMsg0.type) } // required uint32 epid = 2; inline bool MessageMsg0::has_epid() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void MessageMsg0::set_has_epid() { _has_bits_[0] |= 0x00000002u; } inline void MessageMsg0::clear_has_epid() { _has_bits_[0] &= ~0x00000002u; } inline void MessageMsg0::clear_epid() { epid_ = 0u; clear_has_epid(); } inline ::google::protobuf::uint32 MessageMsg0::epid() const { // @@protoc_insertion_point(field_get:Messages.MessageMsg0.epid) return epid_; } inline void MessageMsg0::set_epid(::google::protobuf::uint32 value) { set_has_epid(); epid_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMsg0.epid) } // optional uint32 status = 3; inline bool MessageMsg0::has_status() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void MessageMsg0::set_has_status() { _has_bits_[0] |= 0x00000004u; } inline void MessageMsg0::clear_has_status() { _has_bits_[0] &= ~0x00000004u; } inline void MessageMsg0::clear_status() { status_ = 0u; clear_has_status(); } inline ::google::protobuf::uint32 MessageMsg0::status() const { // @@protoc_insertion_point(field_get:Messages.MessageMsg0.status) return status_; } inline void MessageMsg0::set_status(::google::protobuf::uint32 value) { set_has_status(); status_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMsg0.status) } // ------------------------------------------------------------------- // MessageMSG1 // required uint32 type = 1; inline bool MessageMSG1::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void MessageMSG1::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void MessageMSG1::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void MessageMSG1::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 MessageMSG1::type() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG1.type) return type_; } inline void MessageMSG1::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG1.type) } // required uint32 context = 2; inline bool MessageMSG1::has_context() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void MessageMSG1::set_has_context() { _has_bits_[0] |= 0x00000002u; } inline void MessageMSG1::clear_has_context() { _has_bits_[0] &= ~0x00000002u; } inline void MessageMSG1::clear_context() { context_ = 0u; clear_has_context(); } inline ::google::protobuf::uint32 MessageMSG1::context() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG1.context) return context_; } inline void MessageMSG1::set_context(::google::protobuf::uint32 value) { set_has_context(); context_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG1.context) } // repeated uint32 GaX = 3 [packed = true]; inline int MessageMSG1::gax_size() const { return gax_.size(); } inline void MessageMSG1::clear_gax() { gax_.Clear(); } inline ::google::protobuf::uint32 MessageMSG1::gax(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG1.GaX) return gax_.Get(index); } inline void MessageMSG1::set_gax(int index, ::google::protobuf::uint32 value) { gax_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG1.GaX) } inline void MessageMSG1::add_gax(::google::protobuf::uint32 value) { gax_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG1.GaX) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG1::gax() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG1.GaX) return gax_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG1::mutable_gax() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG1.GaX) return &gax_; } // repeated uint32 GaY = 4 [packed = true]; inline int MessageMSG1::gay_size() const { return gay_.size(); } inline void MessageMSG1::clear_gay() { gay_.Clear(); } inline ::google::protobuf::uint32 MessageMSG1::gay(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG1.GaY) return gay_.Get(index); } inline void MessageMSG1::set_gay(int index, ::google::protobuf::uint32 value) { gay_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG1.GaY) } inline void MessageMSG1::add_gay(::google::protobuf::uint32 value) { gay_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG1.GaY) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG1::gay() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG1.GaY) return gay_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG1::mutable_gay() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG1.GaY) return &gay_; } // repeated uint32 GID = 5 [packed = true]; inline int MessageMSG1::gid_size() const { return gid_.size(); } inline void MessageMSG1::clear_gid() { gid_.Clear(); } inline ::google::protobuf::uint32 MessageMSG1::gid(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG1.GID) return gid_.Get(index); } inline void MessageMSG1::set_gid(int index, ::google::protobuf::uint32 value) { gid_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG1.GID) } inline void MessageMSG1::add_gid(::google::protobuf::uint32 value) { gid_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG1.GID) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG1::gid() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG1.GID) return gid_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG1::mutable_gid() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG1.GID) return &gid_; } // ------------------------------------------------------------------- // MessageMSG2 // required uint32 type = 1; inline bool MessageMSG2::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void MessageMSG2::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void MessageMSG2::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void MessageMSG2::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 MessageMSG2::type() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.type) return type_; } inline void MessageMSG2::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG2.type) } // optional uint32 size = 2; inline bool MessageMSG2::has_size() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void MessageMSG2::set_has_size() { _has_bits_[0] |= 0x00000002u; } inline void MessageMSG2::clear_has_size() { _has_bits_[0] &= ~0x00000002u; } inline void MessageMSG2::clear_size() { size_ = 0u; clear_has_size(); } inline ::google::protobuf::uint32 MessageMSG2::size() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.size) return size_; } inline void MessageMSG2::set_size(::google::protobuf::uint32 value) { set_has_size(); size_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG2.size) } // required uint32 context = 3; inline bool MessageMSG2::has_context() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void MessageMSG2::set_has_context() { _has_bits_[0] |= 0x00000004u; } inline void MessageMSG2::clear_has_context() { _has_bits_[0] &= ~0x00000004u; } inline void MessageMSG2::clear_context() { context_ = 0u; clear_has_context(); } inline ::google::protobuf::uint32 MessageMSG2::context() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.context) return context_; } inline void MessageMSG2::set_context(::google::protobuf::uint32 value) { set_has_context(); context_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG2.context) } // repeated uint32 public_key_gx = 4 [packed = true]; inline int MessageMSG2::public_key_gx_size() const { return public_key_gx_.size(); } inline void MessageMSG2::clear_public_key_gx() { public_key_gx_.Clear(); } inline ::google::protobuf::uint32 MessageMSG2::public_key_gx(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.public_key_gx) return public_key_gx_.Get(index); } inline void MessageMSG2::set_public_key_gx(int index, ::google::protobuf::uint32 value) { public_key_gx_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG2.public_key_gx) } inline void MessageMSG2::add_public_key_gx(::google::protobuf::uint32 value) { public_key_gx_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG2.public_key_gx) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG2::public_key_gx() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG2.public_key_gx) return public_key_gx_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG2::mutable_public_key_gx() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG2.public_key_gx) return &public_key_gx_; } // repeated uint32 public_key_gy = 5 [packed = true]; inline int MessageMSG2::public_key_gy_size() const { return public_key_gy_.size(); } inline void MessageMSG2::clear_public_key_gy() { public_key_gy_.Clear(); } inline ::google::protobuf::uint32 MessageMSG2::public_key_gy(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.public_key_gy) return public_key_gy_.Get(index); } inline void MessageMSG2::set_public_key_gy(int index, ::google::protobuf::uint32 value) { public_key_gy_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG2.public_key_gy) } inline void MessageMSG2::add_public_key_gy(::google::protobuf::uint32 value) { public_key_gy_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG2.public_key_gy) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG2::public_key_gy() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG2.public_key_gy) return public_key_gy_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG2::mutable_public_key_gy() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG2.public_key_gy) return &public_key_gy_; } // optional uint32 quote_type = 6; inline bool MessageMSG2::has_quote_type() const { return (_has_bits_[0] & 0x00000020u) != 0; } inline void MessageMSG2::set_has_quote_type() { _has_bits_[0] |= 0x00000020u; } inline void MessageMSG2::clear_has_quote_type() { _has_bits_[0] &= ~0x00000020u; } inline void MessageMSG2::clear_quote_type() { quote_type_ = 0u; clear_has_quote_type(); } inline ::google::protobuf::uint32 MessageMSG2::quote_type() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.quote_type) return quote_type_; } inline void MessageMSG2::set_quote_type(::google::protobuf::uint32 value) { set_has_quote_type(); quote_type_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG2.quote_type) } // repeated uint32 spid = 7 [packed = true]; inline int MessageMSG2::spid_size() const { return spid_.size(); } inline void MessageMSG2::clear_spid() { spid_.Clear(); } inline ::google::protobuf::uint32 MessageMSG2::spid(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.spid) return spid_.Get(index); } inline void MessageMSG2::set_spid(int index, ::google::protobuf::uint32 value) { spid_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG2.spid) } inline void MessageMSG2::add_spid(::google::protobuf::uint32 value) { spid_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG2.spid) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG2::spid() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG2.spid) return spid_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG2::mutable_spid() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG2.spid) return &spid_; } // optional uint32 cmac_kdf_id = 8; inline bool MessageMSG2::has_cmac_kdf_id() const { return (_has_bits_[0] & 0x00000080u) != 0; } inline void MessageMSG2::set_has_cmac_kdf_id() { _has_bits_[0] |= 0x00000080u; } inline void MessageMSG2::clear_has_cmac_kdf_id() { _has_bits_[0] &= ~0x00000080u; } inline void MessageMSG2::clear_cmac_kdf_id() { cmac_kdf_id_ = 0u; clear_has_cmac_kdf_id(); } inline ::google::protobuf::uint32 MessageMSG2::cmac_kdf_id() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.cmac_kdf_id) return cmac_kdf_id_; } inline void MessageMSG2::set_cmac_kdf_id(::google::protobuf::uint32 value) { set_has_cmac_kdf_id(); cmac_kdf_id_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG2.cmac_kdf_id) } // repeated uint32 signature_x = 9 [packed = true]; inline int MessageMSG2::signature_x_size() const { return signature_x_.size(); } inline void MessageMSG2::clear_signature_x() { signature_x_.Clear(); } inline ::google::protobuf::uint32 MessageMSG2::signature_x(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.signature_x) return signature_x_.Get(index); } inline void MessageMSG2::set_signature_x(int index, ::google::protobuf::uint32 value) { signature_x_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG2.signature_x) } inline void MessageMSG2::add_signature_x(::google::protobuf::uint32 value) { signature_x_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG2.signature_x) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG2::signature_x() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG2.signature_x) return signature_x_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG2::mutable_signature_x() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG2.signature_x) return &signature_x_; } // repeated uint32 signature_y = 10 [packed = true]; inline int MessageMSG2::signature_y_size() const { return signature_y_.size(); } inline void MessageMSG2::clear_signature_y() { signature_y_.Clear(); } inline ::google::protobuf::uint32 MessageMSG2::signature_y(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.signature_y) return signature_y_.Get(index); } inline void MessageMSG2::set_signature_y(int index, ::google::protobuf::uint32 value) { signature_y_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG2.signature_y) } inline void MessageMSG2::add_signature_y(::google::protobuf::uint32 value) { signature_y_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG2.signature_y) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG2::signature_y() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG2.signature_y) return signature_y_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG2::mutable_signature_y() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG2.signature_y) return &signature_y_; } // repeated uint32 smac = 11 [packed = true]; inline int MessageMSG2::smac_size() const { return smac_.size(); } inline void MessageMSG2::clear_smac() { smac_.Clear(); } inline ::google::protobuf::uint32 MessageMSG2::smac(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.smac) return smac_.Get(index); } inline void MessageMSG2::set_smac(int index, ::google::protobuf::uint32 value) { smac_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG2.smac) } inline void MessageMSG2::add_smac(::google::protobuf::uint32 value) { smac_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG2.smac) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG2::smac() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG2.smac) return smac_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG2::mutable_smac() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG2.smac) return &smac_; } // optional uint32 size_sigrl = 12; inline bool MessageMSG2::has_size_sigrl() const { return (_has_bits_[0] & 0x00000800u) != 0; } inline void MessageMSG2::set_has_size_sigrl() { _has_bits_[0] |= 0x00000800u; } inline void MessageMSG2::clear_has_size_sigrl() { _has_bits_[0] &= ~0x00000800u; } inline void MessageMSG2::clear_size_sigrl() { size_sigrl_ = 0u; clear_has_size_sigrl(); } inline ::google::protobuf::uint32 MessageMSG2::size_sigrl() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.size_sigrl) return size_sigrl_; } inline void MessageMSG2::set_size_sigrl(::google::protobuf::uint32 value) { set_has_size_sigrl(); size_sigrl_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG2.size_sigrl) } // repeated uint32 sigrl = 13 [packed = true]; inline int MessageMSG2::sigrl_size() const { return sigrl_.size(); } inline void MessageMSG2::clear_sigrl() { sigrl_.Clear(); } inline ::google::protobuf::uint32 MessageMSG2::sigrl(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG2.sigrl) return sigrl_.Get(index); } inline void MessageMSG2::set_sigrl(int index, ::google::protobuf::uint32 value) { sigrl_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG2.sigrl) } inline void MessageMSG2::add_sigrl(::google::protobuf::uint32 value) { sigrl_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG2.sigrl) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG2::sigrl() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG2.sigrl) return sigrl_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG2::mutable_sigrl() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG2.sigrl) return &sigrl_; } // ------------------------------------------------------------------- // MessageMSG3 // required uint32 type = 1; inline bool MessageMSG3::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void MessageMSG3::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void MessageMSG3::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void MessageMSG3::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 MessageMSG3::type() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG3.type) return type_; } inline void MessageMSG3::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG3.type) } // optional uint32 size = 2; inline bool MessageMSG3::has_size() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void MessageMSG3::set_has_size() { _has_bits_[0] |= 0x00000002u; } inline void MessageMSG3::clear_has_size() { _has_bits_[0] &= ~0x00000002u; } inline void MessageMSG3::clear_size() { size_ = 0u; clear_has_size(); } inline ::google::protobuf::uint32 MessageMSG3::size() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG3.size) return size_; } inline void MessageMSG3::set_size(::google::protobuf::uint32 value) { set_has_size(); size_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG3.size) } // required uint32 context = 3; inline bool MessageMSG3::has_context() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void MessageMSG3::set_has_context() { _has_bits_[0] |= 0x00000004u; } inline void MessageMSG3::clear_has_context() { _has_bits_[0] &= ~0x00000004u; } inline void MessageMSG3::clear_context() { context_ = 0u; clear_has_context(); } inline ::google::protobuf::uint32 MessageMSG3::context() const { // @@protoc_insertion_point(field_get:Messages.MessageMSG3.context) return context_; } inline void MessageMSG3::set_context(::google::protobuf::uint32 value) { set_has_context(); context_ = value; // @@protoc_insertion_point(field_set:Messages.MessageMSG3.context) } // repeated uint32 sgx_mac = 4 [packed = true]; inline int MessageMSG3::sgx_mac_size() const { return sgx_mac_.size(); } inline void MessageMSG3::clear_sgx_mac() { sgx_mac_.Clear(); } inline ::google::protobuf::uint32 MessageMSG3::sgx_mac(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG3.sgx_mac) return sgx_mac_.Get(index); } inline void MessageMSG3::set_sgx_mac(int index, ::google::protobuf::uint32 value) { sgx_mac_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG3.sgx_mac) } inline void MessageMSG3::add_sgx_mac(::google::protobuf::uint32 value) { sgx_mac_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG3.sgx_mac) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG3::sgx_mac() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG3.sgx_mac) return sgx_mac_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG3::mutable_sgx_mac() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG3.sgx_mac) return &sgx_mac_; } // repeated uint32 gax_msg3 = 5 [packed = true]; inline int MessageMSG3::gax_msg3_size() const { return gax_msg3_.size(); } inline void MessageMSG3::clear_gax_msg3() { gax_msg3_.Clear(); } inline ::google::protobuf::uint32 MessageMSG3::gax_msg3(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG3.gax_msg3) return gax_msg3_.Get(index); } inline void MessageMSG3::set_gax_msg3(int index, ::google::protobuf::uint32 value) { gax_msg3_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG3.gax_msg3) } inline void MessageMSG3::add_gax_msg3(::google::protobuf::uint32 value) { gax_msg3_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG3.gax_msg3) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG3::gax_msg3() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG3.gax_msg3) return gax_msg3_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG3::mutable_gax_msg3() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG3.gax_msg3) return &gax_msg3_; } // repeated uint32 gay_msg3 = 6 [packed = true]; inline int MessageMSG3::gay_msg3_size() const { return gay_msg3_.size(); } inline void MessageMSG3::clear_gay_msg3() { gay_msg3_.Clear(); } inline ::google::protobuf::uint32 MessageMSG3::gay_msg3(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG3.gay_msg3) return gay_msg3_.Get(index); } inline void MessageMSG3::set_gay_msg3(int index, ::google::protobuf::uint32 value) { gay_msg3_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG3.gay_msg3) } inline void MessageMSG3::add_gay_msg3(::google::protobuf::uint32 value) { gay_msg3_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG3.gay_msg3) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG3::gay_msg3() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG3.gay_msg3) return gay_msg3_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG3::mutable_gay_msg3() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG3.gay_msg3) return &gay_msg3_; } // repeated uint32 sec_property = 7 [packed = true]; inline int MessageMSG3::sec_property_size() const { return sec_property_.size(); } inline void MessageMSG3::clear_sec_property() { sec_property_.Clear(); } inline ::google::protobuf::uint32 MessageMSG3::sec_property(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG3.sec_property) return sec_property_.Get(index); } inline void MessageMSG3::set_sec_property(int index, ::google::protobuf::uint32 value) { sec_property_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG3.sec_property) } inline void MessageMSG3::add_sec_property(::google::protobuf::uint32 value) { sec_property_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG3.sec_property) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG3::sec_property() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG3.sec_property) return sec_property_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG3::mutable_sec_property() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG3.sec_property) return &sec_property_; } // repeated uint32 quote = 8 [packed = true]; inline int MessageMSG3::quote_size() const { return quote_.size(); } inline void MessageMSG3::clear_quote() { quote_.Clear(); } inline ::google::protobuf::uint32 MessageMSG3::quote(int index) const { // @@protoc_insertion_point(field_get:Messages.MessageMSG3.quote) return quote_.Get(index); } inline void MessageMSG3::set_quote(int index, ::google::protobuf::uint32 value) { quote_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessageMSG3.quote) } inline void MessageMSG3::add_quote(::google::protobuf::uint32 value) { quote_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessageMSG3.quote) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessageMSG3::quote() const { // @@protoc_insertion_point(field_list:Messages.MessageMSG3.quote) return quote_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessageMSG3::mutable_quote() { // @@protoc_insertion_point(field_mutable_list:Messages.MessageMSG3.quote) return &quote_; } // ------------------------------------------------------------------- // AttestationMessage // required uint32 type = 1; inline bool AttestationMessage::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void AttestationMessage::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void AttestationMessage::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void AttestationMessage::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 AttestationMessage::type() const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.type) return type_; } inline void AttestationMessage::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.AttestationMessage.type) } // required uint32 size = 2; inline bool AttestationMessage::has_size() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void AttestationMessage::set_has_size() { _has_bits_[0] |= 0x00000002u; } inline void AttestationMessage::clear_has_size() { _has_bits_[0] &= ~0x00000002u; } inline void AttestationMessage::clear_size() { size_ = 0u; clear_has_size(); } inline ::google::protobuf::uint32 AttestationMessage::size() const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.size) return size_; } inline void AttestationMessage::set_size(::google::protobuf::uint32 value) { set_has_size(); size_ = value; // @@protoc_insertion_point(field_set:Messages.AttestationMessage.size) } // required uint32 context = 3; inline bool AttestationMessage::has_context() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void AttestationMessage::set_has_context() { _has_bits_[0] |= 0x00000004u; } inline void AttestationMessage::clear_has_context() { _has_bits_[0] &= ~0x00000004u; } inline void AttestationMessage::clear_context() { context_ = 0u; clear_has_context(); } inline ::google::protobuf::uint32 AttestationMessage::context() const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.context) return context_; } inline void AttestationMessage::set_context(::google::protobuf::uint32 value) { set_has_context(); context_ = value; // @@protoc_insertion_point(field_set:Messages.AttestationMessage.context) } // optional uint32 epid_group_status = 4; inline bool AttestationMessage::has_epid_group_status() const { return (_has_bits_[0] & 0x00000008u) != 0; } inline void AttestationMessage::set_has_epid_group_status() { _has_bits_[0] |= 0x00000008u; } inline void AttestationMessage::clear_has_epid_group_status() { _has_bits_[0] &= ~0x00000008u; } inline void AttestationMessage::clear_epid_group_status() { epid_group_status_ = 0u; clear_has_epid_group_status(); } inline ::google::protobuf::uint32 AttestationMessage::epid_group_status() const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.epid_group_status) return epid_group_status_; } inline void AttestationMessage::set_epid_group_status(::google::protobuf::uint32 value) { set_has_epid_group_status(); epid_group_status_ = value; // @@protoc_insertion_point(field_set:Messages.AttestationMessage.epid_group_status) } // optional uint32 tcb_evaluation_status = 5; inline bool AttestationMessage::has_tcb_evaluation_status() const { return (_has_bits_[0] & 0x00000010u) != 0; } inline void AttestationMessage::set_has_tcb_evaluation_status() { _has_bits_[0] |= 0x00000010u; } inline void AttestationMessage::clear_has_tcb_evaluation_status() { _has_bits_[0] &= ~0x00000010u; } inline void AttestationMessage::clear_tcb_evaluation_status() { tcb_evaluation_status_ = 0u; clear_has_tcb_evaluation_status(); } inline ::google::protobuf::uint32 AttestationMessage::tcb_evaluation_status() const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.tcb_evaluation_status) return tcb_evaluation_status_; } inline void AttestationMessage::set_tcb_evaluation_status(::google::protobuf::uint32 value) { set_has_tcb_evaluation_status(); tcb_evaluation_status_ = value; // @@protoc_insertion_point(field_set:Messages.AttestationMessage.tcb_evaluation_status) } // optional uint32 pse_evaluation_status = 6; inline bool AttestationMessage::has_pse_evaluation_status() const { return (_has_bits_[0] & 0x00000020u) != 0; } inline void AttestationMessage::set_has_pse_evaluation_status() { _has_bits_[0] |= 0x00000020u; } inline void AttestationMessage::clear_has_pse_evaluation_status() { _has_bits_[0] &= ~0x00000020u; } inline void AttestationMessage::clear_pse_evaluation_status() { pse_evaluation_status_ = 0u; clear_has_pse_evaluation_status(); } inline ::google::protobuf::uint32 AttestationMessage::pse_evaluation_status() const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.pse_evaluation_status) return pse_evaluation_status_; } inline void AttestationMessage::set_pse_evaluation_status(::google::protobuf::uint32 value) { set_has_pse_evaluation_status(); pse_evaluation_status_ = value; // @@protoc_insertion_point(field_set:Messages.AttestationMessage.pse_evaluation_status) } // repeated uint32 latest_equivalent_tcb_psvn = 7 [packed = true]; inline int AttestationMessage::latest_equivalent_tcb_psvn_size() const { return latest_equivalent_tcb_psvn_.size(); } inline void AttestationMessage::clear_latest_equivalent_tcb_psvn() { latest_equivalent_tcb_psvn_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::latest_equivalent_tcb_psvn(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.latest_equivalent_tcb_psvn) return latest_equivalent_tcb_psvn_.Get(index); } inline void AttestationMessage::set_latest_equivalent_tcb_psvn(int index, ::google::protobuf::uint32 value) { latest_equivalent_tcb_psvn_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.latest_equivalent_tcb_psvn) } inline void AttestationMessage::add_latest_equivalent_tcb_psvn(::google::protobuf::uint32 value) { latest_equivalent_tcb_psvn_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.latest_equivalent_tcb_psvn) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::latest_equivalent_tcb_psvn() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.latest_equivalent_tcb_psvn) return latest_equivalent_tcb_psvn_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_latest_equivalent_tcb_psvn() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.latest_equivalent_tcb_psvn) return &latest_equivalent_tcb_psvn_; } // repeated uint32 latest_pse_isvsvn = 8 [packed = true]; inline int AttestationMessage::latest_pse_isvsvn_size() const { return latest_pse_isvsvn_.size(); } inline void AttestationMessage::clear_latest_pse_isvsvn() { latest_pse_isvsvn_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::latest_pse_isvsvn(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.latest_pse_isvsvn) return latest_pse_isvsvn_.Get(index); } inline void AttestationMessage::set_latest_pse_isvsvn(int index, ::google::protobuf::uint32 value) { latest_pse_isvsvn_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.latest_pse_isvsvn) } inline void AttestationMessage::add_latest_pse_isvsvn(::google::protobuf::uint32 value) { latest_pse_isvsvn_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.latest_pse_isvsvn) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::latest_pse_isvsvn() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.latest_pse_isvsvn) return latest_pse_isvsvn_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_latest_pse_isvsvn() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.latest_pse_isvsvn) return &latest_pse_isvsvn_; } // repeated uint32 latest_psda_svn = 9 [packed = true]; inline int AttestationMessage::latest_psda_svn_size() const { return latest_psda_svn_.size(); } inline void AttestationMessage::clear_latest_psda_svn() { latest_psda_svn_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::latest_psda_svn(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.latest_psda_svn) return latest_psda_svn_.Get(index); } inline void AttestationMessage::set_latest_psda_svn(int index, ::google::protobuf::uint32 value) { latest_psda_svn_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.latest_psda_svn) } inline void AttestationMessage::add_latest_psda_svn(::google::protobuf::uint32 value) { latest_psda_svn_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.latest_psda_svn) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::latest_psda_svn() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.latest_psda_svn) return latest_psda_svn_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_latest_psda_svn() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.latest_psda_svn) return &latest_psda_svn_; } // repeated uint32 performance_rekey_gid = 10 [packed = true]; inline int AttestationMessage::performance_rekey_gid_size() const { return performance_rekey_gid_.size(); } inline void AttestationMessage::clear_performance_rekey_gid() { performance_rekey_gid_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::performance_rekey_gid(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.performance_rekey_gid) return performance_rekey_gid_.Get(index); } inline void AttestationMessage::set_performance_rekey_gid(int index, ::google::protobuf::uint32 value) { performance_rekey_gid_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.performance_rekey_gid) } inline void AttestationMessage::add_performance_rekey_gid(::google::protobuf::uint32 value) { performance_rekey_gid_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.performance_rekey_gid) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::performance_rekey_gid() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.performance_rekey_gid) return performance_rekey_gid_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_performance_rekey_gid() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.performance_rekey_gid) return &performance_rekey_gid_; } // repeated uint32 ec_sign256_x = 11 [packed = true]; inline int AttestationMessage::ec_sign256_x_size() const { return ec_sign256_x_.size(); } inline void AttestationMessage::clear_ec_sign256_x() { ec_sign256_x_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::ec_sign256_x(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.ec_sign256_x) return ec_sign256_x_.Get(index); } inline void AttestationMessage::set_ec_sign256_x(int index, ::google::protobuf::uint32 value) { ec_sign256_x_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.ec_sign256_x) } inline void AttestationMessage::add_ec_sign256_x(::google::protobuf::uint32 value) { ec_sign256_x_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.ec_sign256_x) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::ec_sign256_x() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.ec_sign256_x) return ec_sign256_x_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_ec_sign256_x() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.ec_sign256_x) return &ec_sign256_x_; } // repeated uint32 ec_sign256_y = 12 [packed = true]; inline int AttestationMessage::ec_sign256_y_size() const { return ec_sign256_y_.size(); } inline void AttestationMessage::clear_ec_sign256_y() { ec_sign256_y_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::ec_sign256_y(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.ec_sign256_y) return ec_sign256_y_.Get(index); } inline void AttestationMessage::set_ec_sign256_y(int index, ::google::protobuf::uint32 value) { ec_sign256_y_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.ec_sign256_y) } inline void AttestationMessage::add_ec_sign256_y(::google::protobuf::uint32 value) { ec_sign256_y_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.ec_sign256_y) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::ec_sign256_y() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.ec_sign256_y) return ec_sign256_y_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_ec_sign256_y() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.ec_sign256_y) return &ec_sign256_y_; } // repeated uint32 mac_smk = 13 [packed = true]; inline int AttestationMessage::mac_smk_size() const { return mac_smk_.size(); } inline void AttestationMessage::clear_mac_smk() { mac_smk_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::mac_smk(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.mac_smk) return mac_smk_.Get(index); } inline void AttestationMessage::set_mac_smk(int index, ::google::protobuf::uint32 value) { mac_smk_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.mac_smk) } inline void AttestationMessage::add_mac_smk(::google::protobuf::uint32 value) { mac_smk_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.mac_smk) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::mac_smk() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.mac_smk) return mac_smk_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_mac_smk() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.mac_smk) return &mac_smk_; } // optional uint32 result_size = 14; inline bool AttestationMessage::has_result_size() const { return (_has_bits_[0] & 0x00002000u) != 0; } inline void AttestationMessage::set_has_result_size() { _has_bits_[0] |= 0x00002000u; } inline void AttestationMessage::clear_has_result_size() { _has_bits_[0] &= ~0x00002000u; } inline void AttestationMessage::clear_result_size() { result_size_ = 0u; clear_has_result_size(); } inline ::google::protobuf::uint32 AttestationMessage::result_size() const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.result_size) return result_size_; } inline void AttestationMessage::set_result_size(::google::protobuf::uint32 value) { set_has_result_size(); result_size_ = value; // @@protoc_insertion_point(field_set:Messages.AttestationMessage.result_size) } // repeated uint32 reserved = 15 [packed = true]; inline int AttestationMessage::reserved_size() const { return reserved_.size(); } inline void AttestationMessage::clear_reserved() { reserved_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::reserved(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.reserved) return reserved_.Get(index); } inline void AttestationMessage::set_reserved(int index, ::google::protobuf::uint32 value) { reserved_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.reserved) } inline void AttestationMessage::add_reserved(::google::protobuf::uint32 value) { reserved_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.reserved) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::reserved() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.reserved) return reserved_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_reserved() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.reserved) return &reserved_; } // repeated uint32 payload_tag = 16 [packed = true]; inline int AttestationMessage::payload_tag_size() const { return payload_tag_.size(); } inline void AttestationMessage::clear_payload_tag() { payload_tag_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::payload_tag(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.payload_tag) return payload_tag_.Get(index); } inline void AttestationMessage::set_payload_tag(int index, ::google::protobuf::uint32 value) { payload_tag_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.payload_tag) } inline void AttestationMessage::add_payload_tag(::google::protobuf::uint32 value) { payload_tag_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.payload_tag) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::payload_tag() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.payload_tag) return payload_tag_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_payload_tag() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.payload_tag) return &payload_tag_; } // repeated uint32 payload = 17 [packed = true]; inline int AttestationMessage::payload_size() const { return payload_.size(); } inline void AttestationMessage::clear_payload() { payload_.Clear(); } inline ::google::protobuf::uint32 AttestationMessage::payload(int index) const { // @@protoc_insertion_point(field_get:Messages.AttestationMessage.payload) return payload_.Get(index); } inline void AttestationMessage::set_payload(int index, ::google::protobuf::uint32 value) { payload_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.AttestationMessage.payload) } inline void AttestationMessage::add_payload(::google::protobuf::uint32 value) { payload_.Add(value); // @@protoc_insertion_point(field_add:Messages.AttestationMessage.payload) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& AttestationMessage::payload() const { // @@protoc_insertion_point(field_list:Messages.AttestationMessage.payload) return payload_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* AttestationMessage::mutable_payload() { // @@protoc_insertion_point(field_mutable_list:Messages.AttestationMessage.payload) return &payload_; } // ------------------------------------------------------------------- // MessagePsiSalt // required uint32 type = 1; inline bool MessagePsiSalt::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void MessagePsiSalt::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void MessagePsiSalt::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void MessagePsiSalt::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 MessagePsiSalt::type() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiSalt.type) return type_; } inline void MessagePsiSalt::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiSalt.type) } // required uint32 size = 2; inline bool MessagePsiSalt::has_size() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void MessagePsiSalt::set_has_size() { _has_bits_[0] |= 0x00000002u; } inline void MessagePsiSalt::clear_has_size() { _has_bits_[0] &= ~0x00000002u; } inline void MessagePsiSalt::clear_size() { size_ = 0u; clear_has_size(); } inline ::google::protobuf::uint32 MessagePsiSalt::size() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiSalt.size) return size_; } inline void MessagePsiSalt::set_size(::google::protobuf::uint32 value) { set_has_size(); size_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiSalt.size) } // required uint32 context = 3; inline bool MessagePsiSalt::has_context() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void MessagePsiSalt::set_has_context() { _has_bits_[0] |= 0x00000004u; } inline void MessagePsiSalt::clear_has_context() { _has_bits_[0] &= ~0x00000004u; } inline void MessagePsiSalt::clear_context() { context_ = 0u; clear_has_context(); } inline ::google::protobuf::uint32 MessagePsiSalt::context() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiSalt.context) return context_; } inline void MessagePsiSalt::set_context(::google::protobuf::uint32 value) { set_has_context(); context_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiSalt.context) } // required uint32 id = 4; inline bool MessagePsiSalt::has_id() const { return (_has_bits_[0] & 0x00000008u) != 0; } inline void MessagePsiSalt::set_has_id() { _has_bits_[0] |= 0x00000008u; } inline void MessagePsiSalt::clear_has_id() { _has_bits_[0] &= ~0x00000008u; } inline void MessagePsiSalt::clear_id() { id_ = 0u; clear_has_id(); } inline ::google::protobuf::uint32 MessagePsiSalt::id() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiSalt.id) return id_; } inline void MessagePsiSalt::set_id(::google::protobuf::uint32 value) { set_has_id(); id_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiSalt.id) } // required uint32 state = 5; inline bool MessagePsiSalt::has_state() const { return (_has_bits_[0] & 0x00000010u) != 0; } inline void MessagePsiSalt::set_has_state() { _has_bits_[0] |= 0x00000010u; } inline void MessagePsiSalt::clear_has_state() { _has_bits_[0] &= ~0x00000010u; } inline void MessagePsiSalt::clear_state() { state_ = 0u; clear_has_state(); } inline ::google::protobuf::uint32 MessagePsiSalt::state() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiSalt.state) return state_; } inline void MessagePsiSalt::set_state(::google::protobuf::uint32 value) { set_has_state(); state_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiSalt.state) } // repeated uint32 mac = 6 [packed = true]; inline int MessagePsiSalt::mac_size() const { return mac_.size(); } inline void MessagePsiSalt::clear_mac() { mac_.Clear(); } inline ::google::protobuf::uint32 MessagePsiSalt::mac(int index) const { // @@protoc_insertion_point(field_get:Messages.MessagePsiSalt.mac) return mac_.Get(index); } inline void MessagePsiSalt::set_mac(int index, ::google::protobuf::uint32 value) { mac_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessagePsiSalt.mac) } inline void MessagePsiSalt::add_mac(::google::protobuf::uint32 value) { mac_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessagePsiSalt.mac) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessagePsiSalt::mac() const { // @@protoc_insertion_point(field_list:Messages.MessagePsiSalt.mac) return mac_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessagePsiSalt::mutable_mac() { // @@protoc_insertion_point(field_mutable_list:Messages.MessagePsiSalt.mac) return &mac_; } // repeated uint32 salt = 7 [packed = true]; inline int MessagePsiSalt::salt_size() const { return salt_.size(); } inline void MessagePsiSalt::clear_salt() { salt_.Clear(); } inline ::google::protobuf::uint32 MessagePsiSalt::salt(int index) const { // @@protoc_insertion_point(field_get:Messages.MessagePsiSalt.salt) return salt_.Get(index); } inline void MessagePsiSalt::set_salt(int index, ::google::protobuf::uint32 value) { salt_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessagePsiSalt.salt) } inline void MessagePsiSalt::add_salt(::google::protobuf::uint32 value) { salt_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessagePsiSalt.salt) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessagePsiSalt::salt() const { // @@protoc_insertion_point(field_list:Messages.MessagePsiSalt.salt) return salt_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessagePsiSalt::mutable_salt() { // @@protoc_insertion_point(field_mutable_list:Messages.MessagePsiSalt.salt) return &salt_; } // ------------------------------------------------------------------- // MessagePsiHashData // required uint32 type = 1; inline bool MessagePsiHashData::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void MessagePsiHashData::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void MessagePsiHashData::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void MessagePsiHashData::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 MessagePsiHashData::type() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashData.type) return type_; } inline void MessagePsiHashData::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiHashData.type) } // required uint32 size = 2; inline bool MessagePsiHashData::has_size() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void MessagePsiHashData::set_has_size() { _has_bits_[0] |= 0x00000002u; } inline void MessagePsiHashData::clear_has_size() { _has_bits_[0] &= ~0x00000002u; } inline void MessagePsiHashData::clear_size() { size_ = 0u; clear_has_size(); } inline ::google::protobuf::uint32 MessagePsiHashData::size() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashData.size) return size_; } inline void MessagePsiHashData::set_size(::google::protobuf::uint32 value) { set_has_size(); size_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiHashData.size) } // required uint32 context = 3; inline bool MessagePsiHashData::has_context() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void MessagePsiHashData::set_has_context() { _has_bits_[0] |= 0x00000004u; } inline void MessagePsiHashData::clear_has_context() { _has_bits_[0] &= ~0x00000004u; } inline void MessagePsiHashData::clear_context() { context_ = 0u; clear_has_context(); } inline ::google::protobuf::uint32 MessagePsiHashData::context() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashData.context) return context_; } inline void MessagePsiHashData::set_context(::google::protobuf::uint32 value) { set_has_context(); context_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiHashData.context) } // required uint32 id = 4; inline bool MessagePsiHashData::has_id() const { return (_has_bits_[0] & 0x00000008u) != 0; } inline void MessagePsiHashData::set_has_id() { _has_bits_[0] |= 0x00000008u; } inline void MessagePsiHashData::clear_has_id() { _has_bits_[0] &= ~0x00000008u; } inline void MessagePsiHashData::clear_id() { id_ = 0u; clear_has_id(); } inline ::google::protobuf::uint32 MessagePsiHashData::id() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashData.id) return id_; } inline void MessagePsiHashData::set_id(::google::protobuf::uint32 value) { set_has_id(); id_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiHashData.id) } // repeated uint32 mac = 5 [packed = true]; inline int MessagePsiHashData::mac_size() const { return mac_.size(); } inline void MessagePsiHashData::clear_mac() { mac_.Clear(); } inline ::google::protobuf::uint32 MessagePsiHashData::mac(int index) const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashData.mac) return mac_.Get(index); } inline void MessagePsiHashData::set_mac(int index, ::google::protobuf::uint32 value) { mac_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessagePsiHashData.mac) } inline void MessagePsiHashData::add_mac(::google::protobuf::uint32 value) { mac_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessagePsiHashData.mac) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessagePsiHashData::mac() const { // @@protoc_insertion_point(field_list:Messages.MessagePsiHashData.mac) return mac_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessagePsiHashData::mutable_mac() { // @@protoc_insertion_point(field_mutable_list:Messages.MessagePsiHashData.mac) return &mac_; } // repeated uint32 data = 6 [packed = true]; inline int MessagePsiHashData::data_size() const { return data_.size(); } inline void MessagePsiHashData::clear_data() { data_.Clear(); } inline ::google::protobuf::uint32 MessagePsiHashData::data(int index) const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashData.data) return data_.Get(index); } inline void MessagePsiHashData::set_data(int index, ::google::protobuf::uint32 value) { data_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessagePsiHashData.data) } inline void MessagePsiHashData::add_data(::google::protobuf::uint32 value) { data_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessagePsiHashData.data) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessagePsiHashData::data() const { // @@protoc_insertion_point(field_list:Messages.MessagePsiHashData.data) return data_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessagePsiHashData::mutable_data() { // @@protoc_insertion_point(field_mutable_list:Messages.MessagePsiHashData.data) return &data_; } // ------------------------------------------------------------------- // MessagePsiHashDataFinished // required uint32 type = 1; inline bool MessagePsiHashDataFinished::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void MessagePsiHashDataFinished::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void MessagePsiHashDataFinished::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void MessagePsiHashDataFinished::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 MessagePsiHashDataFinished::type() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashDataFinished.type) return type_; } inline void MessagePsiHashDataFinished::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiHashDataFinished.type) } // required uint32 size = 2; inline bool MessagePsiHashDataFinished::has_size() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void MessagePsiHashDataFinished::set_has_size() { _has_bits_[0] |= 0x00000002u; } inline void MessagePsiHashDataFinished::clear_has_size() { _has_bits_[0] &= ~0x00000002u; } inline void MessagePsiHashDataFinished::clear_size() { size_ = 0u; clear_has_size(); } inline ::google::protobuf::uint32 MessagePsiHashDataFinished::size() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashDataFinished.size) return size_; } inline void MessagePsiHashDataFinished::set_size(::google::protobuf::uint32 value) { set_has_size(); size_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiHashDataFinished.size) } // required uint32 context = 3; inline bool MessagePsiHashDataFinished::has_context() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void MessagePsiHashDataFinished::set_has_context() { _has_bits_[0] |= 0x00000004u; } inline void MessagePsiHashDataFinished::clear_has_context() { _has_bits_[0] &= ~0x00000004u; } inline void MessagePsiHashDataFinished::clear_context() { context_ = 0u; clear_has_context(); } inline ::google::protobuf::uint32 MessagePsiHashDataFinished::context() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashDataFinished.context) return context_; } inline void MessagePsiHashDataFinished::set_context(::google::protobuf::uint32 value) { set_has_context(); context_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiHashDataFinished.context) } // required uint32 id = 4; inline bool MessagePsiHashDataFinished::has_id() const { return (_has_bits_[0] & 0x00000008u) != 0; } inline void MessagePsiHashDataFinished::set_has_id() { _has_bits_[0] |= 0x00000008u; } inline void MessagePsiHashDataFinished::clear_has_id() { _has_bits_[0] &= ~0x00000008u; } inline void MessagePsiHashDataFinished::clear_id() { id_ = 0u; clear_has_id(); } inline ::google::protobuf::uint32 MessagePsiHashDataFinished::id() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiHashDataFinished.id) return id_; } inline void MessagePsiHashDataFinished::set_id(::google::protobuf::uint32 value) { set_has_id(); id_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiHashDataFinished.id) } // ------------------------------------------------------------------- // MessagePsiResult // required uint32 type = 1; inline bool MessagePsiResult::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void MessagePsiResult::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void MessagePsiResult::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void MessagePsiResult::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 MessagePsiResult::type() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiResult.type) return type_; } inline void MessagePsiResult::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiResult.type) } // required uint32 size = 2; inline bool MessagePsiResult::has_size() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void MessagePsiResult::set_has_size() { _has_bits_[0] |= 0x00000002u; } inline void MessagePsiResult::clear_has_size() { _has_bits_[0] &= ~0x00000002u; } inline void MessagePsiResult::clear_size() { size_ = 0u; clear_has_size(); } inline ::google::protobuf::uint32 MessagePsiResult::size() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiResult.size) return size_; } inline void MessagePsiResult::set_size(::google::protobuf::uint32 value) { set_has_size(); size_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiResult.size) } // required uint32 context = 3; inline bool MessagePsiResult::has_context() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void MessagePsiResult::set_has_context() { _has_bits_[0] |= 0x00000004u; } inline void MessagePsiResult::clear_has_context() { _has_bits_[0] &= ~0x00000004u; } inline void MessagePsiResult::clear_context() { context_ = 0u; clear_has_context(); } inline ::google::protobuf::uint32 MessagePsiResult::context() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiResult.context) return context_; } inline void MessagePsiResult::set_context(::google::protobuf::uint32 value) { set_has_context(); context_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiResult.context) } // required uint32 id = 4; inline bool MessagePsiResult::has_id() const { return (_has_bits_[0] & 0x00000008u) != 0; } inline void MessagePsiResult::set_has_id() { _has_bits_[0] |= 0x00000008u; } inline void MessagePsiResult::clear_has_id() { _has_bits_[0] &= ~0x00000008u; } inline void MessagePsiResult::clear_id() { id_ = 0u; clear_has_id(); } inline ::google::protobuf::uint32 MessagePsiResult::id() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiResult.id) return id_; } inline void MessagePsiResult::set_id(::google::protobuf::uint32 value) { set_has_id(); id_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiResult.id) } // required uint32 state = 5; inline bool MessagePsiResult::has_state() const { return (_has_bits_[0] & 0x00000010u) != 0; } inline void MessagePsiResult::set_has_state() { _has_bits_[0] |= 0x00000010u; } inline void MessagePsiResult::clear_has_state() { _has_bits_[0] &= ~0x00000010u; } inline void MessagePsiResult::clear_state() { state_ = 0u; clear_has_state(); } inline ::google::protobuf::uint32 MessagePsiResult::state() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiResult.state) return state_; } inline void MessagePsiResult::set_state(::google::protobuf::uint32 value) { set_has_state(); state_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiResult.state) } // ------------------------------------------------------------------- // MessagePsiIntersect // required uint32 type = 1; inline bool MessagePsiIntersect::has_type() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void MessagePsiIntersect::set_has_type() { _has_bits_[0] |= 0x00000001u; } inline void MessagePsiIntersect::clear_has_type() { _has_bits_[0] &= ~0x00000001u; } inline void MessagePsiIntersect::clear_type() { type_ = 0u; clear_has_type(); } inline ::google::protobuf::uint32 MessagePsiIntersect::type() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiIntersect.type) return type_; } inline void MessagePsiIntersect::set_type(::google::protobuf::uint32 value) { set_has_type(); type_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiIntersect.type) } // required uint32 size = 2; inline bool MessagePsiIntersect::has_size() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void MessagePsiIntersect::set_has_size() { _has_bits_[0] |= 0x00000002u; } inline void MessagePsiIntersect::clear_has_size() { _has_bits_[0] &= ~0x00000002u; } inline void MessagePsiIntersect::clear_size() { size_ = 0u; clear_has_size(); } inline ::google::protobuf::uint32 MessagePsiIntersect::size() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiIntersect.size) return size_; } inline void MessagePsiIntersect::set_size(::google::protobuf::uint32 value) { set_has_size(); size_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiIntersect.size) } // required uint32 context = 3; inline bool MessagePsiIntersect::has_context() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void MessagePsiIntersect::set_has_context() { _has_bits_[0] |= 0x00000004u; } inline void MessagePsiIntersect::clear_has_context() { _has_bits_[0] &= ~0x00000004u; } inline void MessagePsiIntersect::clear_context() { context_ = 0u; clear_has_context(); } inline ::google::protobuf::uint32 MessagePsiIntersect::context() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiIntersect.context) return context_; } inline void MessagePsiIntersect::set_context(::google::protobuf::uint32 value) { set_has_context(); context_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiIntersect.context) } // required uint32 id = 4; inline bool MessagePsiIntersect::has_id() const { return (_has_bits_[0] & 0x00000008u) != 0; } inline void MessagePsiIntersect::set_has_id() { _has_bits_[0] |= 0x00000008u; } inline void MessagePsiIntersect::clear_has_id() { _has_bits_[0] &= ~0x00000008u; } inline void MessagePsiIntersect::clear_id() { id_ = 0u; clear_has_id(); } inline ::google::protobuf::uint32 MessagePsiIntersect::id() const { // @@protoc_insertion_point(field_get:Messages.MessagePsiIntersect.id) return id_; } inline void MessagePsiIntersect::set_id(::google::protobuf::uint32 value) { set_has_id(); id_ = value; // @@protoc_insertion_point(field_set:Messages.MessagePsiIntersect.id) } // repeated uint32 mac = 5 [packed = true]; inline int MessagePsiIntersect::mac_size() const { return mac_.size(); } inline void MessagePsiIntersect::clear_mac() { mac_.Clear(); } inline ::google::protobuf::uint32 MessagePsiIntersect::mac(int index) const { // @@protoc_insertion_point(field_get:Messages.MessagePsiIntersect.mac) return mac_.Get(index); } inline void MessagePsiIntersect::set_mac(int index, ::google::protobuf::uint32 value) { mac_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessagePsiIntersect.mac) } inline void MessagePsiIntersect::add_mac(::google::protobuf::uint32 value) { mac_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessagePsiIntersect.mac) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessagePsiIntersect::mac() const { // @@protoc_insertion_point(field_list:Messages.MessagePsiIntersect.mac) return mac_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessagePsiIntersect::mutable_mac() { // @@protoc_insertion_point(field_mutable_list:Messages.MessagePsiIntersect.mac) return &mac_; } // repeated uint32 data = 6 [packed = true]; inline int MessagePsiIntersect::data_size() const { return data_.size(); } inline void MessagePsiIntersect::clear_data() { data_.Clear(); } inline ::google::protobuf::uint32 MessagePsiIntersect::data(int index) const { // @@protoc_insertion_point(field_get:Messages.MessagePsiIntersect.data) return data_.Get(index); } inline void MessagePsiIntersect::set_data(int index, ::google::protobuf::uint32 value) { data_.Set(index, value); // @@protoc_insertion_point(field_set:Messages.MessagePsiIntersect.data) } inline void MessagePsiIntersect::add_data(::google::protobuf::uint32 value) { data_.Add(value); // @@protoc_insertion_point(field_add:Messages.MessagePsiIntersect.data) } inline const ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >& MessagePsiIntersect::data() const { // @@protoc_insertion_point(field_list:Messages.MessagePsiIntersect.data) return data_; } inline ::google::protobuf::RepeatedField< ::google::protobuf::uint32 >* MessagePsiIntersect::mutable_data() { // @@protoc_insertion_point(field_mutable_list:Messages.MessagePsiIntersect.data) return &data_; } #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- // @@protoc_insertion_point(namespace_scope) } // namespace Messages // @@protoc_insertion_point(global_scope) #endif // PROTOBUF_Messages_2eproto__INCLUDED
PelionIoT/pelion-client-lite-example
update_default_resources.c
<reponame>PelionIoT/pelion-client-lite-example //---------------------------------------------------------------------------- // The confidential and proprietary information contained in this file may // only be used by a person authorised under and to the extent permitted // by a subsisting licensing agreement from ARM Limited or its affiliates. // // (C) COPYRIGHT 2016-2020 ARM Limited or its affiliates. // ALL RIGHTS RESERVED // // This entire notice must be reproduced on all copies of this file // and copies of this file may only be made by a person if such person is // permitted to do so under the terms of a subsisting license agreement // from ARM Limited or its affiliates. //---------------------------------------------------------------------------- #ifdef MBED_CLOUD_CLIENT_USER_CONFIG_FILE #include MBED_CLOUD_CLIENT_USER_CONFIG_FILE #endif #include <stdint.h> #ifdef MBED_CLOUD_CLIENT_FOTA_ENABLE #warning "Please run manifest-tool init ... to generate proper update certificates, or disable MBED_CLOUD_CLIENT_SUPPORT_UPDATE" #ifdef MBED_CLOUD_DEV_UPDATE_ID const uint8_t arm_uc_vendor_id[] = { "dev_manufacturer" }; const uint16_t arm_uc_vendor_id_size = sizeof(arm_uc_vendor_id); const uint8_t arm_uc_class_id[] = { "dev_model_number" }; const uint16_t arm_uc_class_id_size = sizeof(arm_uc_class_id); #endif #ifdef MBED_CLOUD_DEV_UPDATE_CERT const uint8_t arm_uc_default_fingerprint[32] = { 0 }; const uint16_t arm_uc_default_fingerprint_size = sizeof(arm_uc_default_fingerprint); const uint8_t arm_uc_default_certificate[1] = { 0 }; const uint16_t arm_uc_default_certificate_size = sizeof(arm_uc_default_certificate); #endif #ifdef MBED_CLOUD_DEV_UPDATE_RAW_PUBLIC_KEY const uint8_t arm_uc_update_public_key[] = { "public_key" }; #endif #ifdef MBED_CLOUD_DEV_UPDATE_PSK const uint8_t arm_uc_default_psk[1] = { 0 }; const uint8_t arm_uc_default_psk_size = sizeof(arm_uc_default_psk); const uint16_t arm_uc_default_psk_bits = sizeof(arm_uc_default_psk) * 8; const uint8_t arm_uc_default_psk_id[1] = { 0 }; const uint8_t arm_uc_default_psk_id_size = sizeof(arm_uc_default_psk_id); #endif #endif // MBED_CLOUD_CLIENT_FOTA_ENABLE
PelionIoT/pelion-client-lite-example
source/fota_platform.c
// ---------------------------------------------------------------------------- // Copyright 2020 ARM Ltd. // // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ---------------------------------------------------------------------------- #include "fota/fota_base.h" #ifdef MBED_CLOUD_CLIENT_FOTA_ENABLE #include "fota/fota_platform_hooks.h" // requied for implementing custom FOTA hooks (init, update start/finish/abort) #include "fota/fota_component.h" // required for registering custom component #include "fota/fota_app_ifs.h" // required for implementing custom install callback for Linux like targets #include <stdio.h> #include <assert.h> // Componenet name - to be updated // This name will be shown on portal and can be used as filter. // When creating an update manifest for this component, this name must be specified as component-name. // Note: must by 9 charecters long - including NULL terminator #define DUMMY_COMPONENT_NAME "BLEexmpl" // Our dummy component does not provide an interface for reading out currently installed FW. // In order to report the current FW to Pelion Device Management portal we need to specify the // initial FW version installed at factory. #define DUMMY_FACTORY_VERSION "0.0.1" #if !defined(TARGET_LIKE_LINUX) static int example_installer(fota_candidate_iterate_callback_info *info); #endif int fota_platform_init_hook(bool after_upgrade) { fota_component_desc_info_t component_descriptor = { #if !defined(TARGET_LIKE_LINUX) .candidate_iterate_cb = example_installer, #endif .need_reboot = true }; int result = fota_component_add( &component_descriptor, DUMMY_COMPONENT_NAME, DUMMY_FACTORY_VERSION); assert(0 == result); return 0; } int fota_platform_start_update_hook(const char *comp_name) { // place holder for handling platform specific setup. // E.g. make sure candidtate storage is ready. return 0; } int fota_platform_finish_update_hook(const char *comp_name) { // place holder for handling platform specific update finish logic return 0; } int fota_platform_abort_update_hook(const char *comp_name) { // place holder for handling platform specific update finish logic return 0; } #if !defined(TARGET_LIKE_LINUX) static int example_installer(fota_candidate_iterate_callback_info *info) { switch (info->status) { case FOTA_CANDIDATE_ITERATE_START: printf(DUMMY_COMPONENT_NAME " - Installation started (example)\n"); printf(DUMMY_COMPONENT_NAME " - Installing "); break; case FOTA_CANDIDATE_ITERATE_FRAGMENT: printf("."); break; case FOTA_CANDIDATE_ITERATE_FINISH: printf("\n" DUMMY_COMPONENT_NAME " - Installation finished (example)\n"); break; default: return FOTA_STATUS_INTERNAL_ERROR; } return 0; } #elif !defined(USE_ACTIVATION_SCRIPT) // e.g. Yocto target have different update activation logic residing outside of the example // Simplified Linux use case example. // For MAIN component update the the binary file current process is running. // Simulate component update by just printing its name. // After the installation callback returns, FOTA will "reboot" by calling mbed_client_default_reboot(). // Default implementation will restart the current process. The behaviour can be changed by injecting // MBED_CLOUD_CLIENT_CUSTOM_REBOOT define to the build and providing an alternative implementation for // mbed_client_default_reboot() function. int fota_app_on_install_candidate(const char *candidate_fs_name, const manifest_firmware_info_t *firmware_info) { int ret = FOTA_STATUS_SUCCESS; if (0 == strncmp(FOTA_COMPONENT_MAIN_COMPONENT_NAME, firmware_info->component_name, FOTA_COMPONENT_MAX_NAME_SIZE)) { // installing MAIN component ret = fota_app_install_main_app(candidate_fs_name); if (FOTA_STATUS_SUCCESS == ret) { printf("Successfully installed MAIN component\n"); // FOTA does support a case where installer method reboots the system. } } else { printf("%s component installed (example)\n", firmware_info->component_name); } return ret; } #endif // !defined(TARGET_LIKE_LINUX) #endif // MBED_CLOUD_CLIENT_FOTA_ENABLE
Orelik11/learning
FutureExpenses/FutureExpenses/User.h
#ifndef __USER_H__ #define __USER_H__ #include <ctime> #include <string> class User { private: struct expenses { tm _day_of_spend; //time when you spent the money unsigned int _sum; // amount of money string _desc; // why you spend them string _category; // for reporting }; struct incomes { tm _day_of_spend; unsigned int _sum; string _desc; string _category; }; public: User(); void add_expense(tm, int, string, string); void add_income(tm, int, string, string); ~User(); }; #endif // !__USER_H__
Orelik11/learning
static_function/static_function/class1.h
#ifndef __CLASS_1_H__ #define __CLASS_1_H__ class CppStudio { public: //int class_counter; CppStudio(); ~CppStudio(); }; #endif
Orelik11/learning
static classes/static classes/CppStudio.h
#pragma once class CppStudio { private: static unsigned int count; public : CppStudio(); ~CppStudio(); static unsigned int CppStudio::getCount(); };
Orelik11/learning
test library/test library/Print.h
#ifndef __LIB_H__ #define __LIB_H__ #include <iostream> namespace Print { void print() { std::cout << "Function print in namespace Print\n"; } } #endif // __LIB_H__
schizobovine/pidplate
firmware/simulator/PID_Simulator.h
#ifndef __PID_SIMULATOR_H #define __PID_SIMULATOR_H #include <stdint.h> #include "usec.h" // Heat "realized" (i.e., made visible to temperature probe) per second (J/s). // This allows a rough approximation of the heat transfer between the coil and // the plate. const double VESTING_RATE = 50.0; // Specific heat capacity. Iron is ~450J/(kg*K) and assuming ~1kg in plate to // make math easier. const double SPECIFIC_HEAT = 450.0; // Power output of hotplate (W) const double PLATE_POWER = 1000.0; // Ambient temp for estimating loss to air w/Newton's Law of Cooling (C) const double AMBIENT_TEMP = 25.0; // Approximate heat loss rate to air (guesstimate of thermal conductivity) const double AMBIENT_LOSS = 0.3; class PIDSimulator { public: PIDSimulator(); void reset(); double calculate(double powerLevel, usec now); double getLastTemp(); double setLastTemp(double temp); double getStoredHeat(); double getFinalTemp(); private: // Internal simulator variables double qVested = 0.0; // Total heat "visible" (J) double qStored = 0.0; // Total heat not yet "visible" (J) double lastTemp = 0.0; // Last temperature measurement (C) usec lastTime = 0; // Epoch time of last temperature measurement (s) // Simulator tunings double vestRate = VESTING_RATE; double heatCap = SPECIFIC_HEAT; double power = PLATE_POWER; double ambient = AMBIENT_TEMP; double qLoss = AMBIENT_LOSS; }; typedef class PIDSimulator PIDSim; #endif
schizobovine/pidplate
firmware/logger/pidplate.h
#ifndef __PIDPLATE_H #define __PIDPLATE_H // // Pins used for thermocouple sensor // const int THERMO_DO = 8; const int THERMO_CS = 9; const int THERMO_CLK = 10; const int SSR = 3; // // Various constants for the OLED display // const int DISPLAY_RST = A3; const int DISPLAY_TEXTSIZE = 1; const int DISPLAY_COLOR = WHITE; const int DISPLAY_ADDR = SSD1306_I2C_ADDRESS; const int DISPLAY_MODE = SSD1306_SWITCHCAPVCC; // // Milliseconds between log outputs // #include "usec.h" const usec LOG_INTERVAL_MS = 1000; // // If the last REPEAT_COUNT temperature readings have been the same, consider // temperature stabilized. // const uint8_t REPEAT_COUNT = 10; // // Length of time (ms) to crank up the SSR and measure the effects. // const usec RUN_TIME = 32 * 1000; // // Duty cycle for SSR (0-255, with 255 being 100%) // const double RUN_LEVEL = 255.0; // // Start message to look for on serial connection // #define TOKEN_START "START" #endif
schizobovine/pidplate
firmware/simulator/PID_Controller.h
<filename>firmware/simulator/PID_Controller.h #ifndef __PID_CONTROLLER_H #define __PID_CONTROLLER_H #include "usec.h" class PIDController { public: /** * Constructor. * * @param input Input variable (aka controlled or process variable (CV/PV) * @param output Output variable (aka manipulated variable (MV) * @param setpt Set point, the value of the input variable we're trying to * hit * @param kp Proportional tuning constant * @param ki Integral tuning constant * @param kd Derrivative tuning constant * @param reversed If true, increasing the output varible DECREASES the * input variable (say, if you're an air conditioner). * @param dt How often we should check and re-evaluate input. THIS VARIABLE * IS WAY MORE IMPORTANT THAN YOU REALIZE. It's the basis for how to * handle the integral and derrivative terms. Thus, a very short * value for a lagging control setup will have hilariously bad * convergence time. * @param outputMin Minimum value for output (to control windup) * @param outputMax Maximum value for output (to control windup) * */ PIDController(double sp, double kp, double ki, double kd); PIDController(); /** * Computes new output value based on current conditions * * @returns True if the output value has changed */ bool compute(usec now); // // Manipulate parameters // void setInput(double newInput); // NO SET OUTPUT void setSP(double newSP); void setKp(double newKp); void setKi(double newKi); void setKd(double newKd); void setReversed(bool newReversed); void setDt(usec newDt); void setOutputMin(double newOutputMin); void setOutputMax(double newOutputMax); // // Frobulate the tunings // void setTuning(double newKp, double newKi, double newKd); void setBounds(double newOutputMin, double newOutputMax); double getInput(); double getOutput(); double getSP(); double getKp(); double getKi(); double getKd(); bool isReversed(); usec getDt(); double getOutputMin(); double getOutputMax(); double getIntegralTerm(); //void serialDebugDump(); private: void setOutput(double newOutput); double input = 0.0; double output = 0.0; double sp = 0.0; double kp = 0.0; double ki = 0.0; double kd = 0.0; bool reversed = false; usec dt = 100L; // We need to know these bounds as we'll liable to overshoot based on the // tuning paramters; if we overshoot, we need to properly account for that // rather than just capping the term (since that still causes ridiculous // overshoot). double outputMin = 0.0; double outputMax = 255.0; // Integral term, to keep up with the accumulated error double iTerm = 0.0; // From the last time calcuate was called usec lastTime = 0L; // Last input value so we can calculate error and approximate its // derrivative double lastInput = 0.0; // Rate of input change from last calculation for second derrivative // approximation (so we can use the velocity form of PID) //double lastDelta = 0.0; }; typedef class PIDController PID; #endif
schizobovine/pidplate
firmware/controller/pidplate.h
<gh_stars>0 #ifndef __PIDPLATE_H #define __PIDPLATE_H // // Pins used for thermocouple sensor // const int THERMO_DO = 8; const int THERMO_CS = 9; const int THERMO_CLK = 10; const int SSR = 3; // // Various constants for the OLED display // const int DISPLAY_RST = A3; const int DISPLAY_TEXTSIZE = 1; const int DISPLAY_COLOR = WHITE; const int DISPLAY_ADDR = SSD1306_I2C_ADDRESS; const int DISPLAY_MODE = SSD1306_SWITCHCAPVCC; // // Tuning parameters // #define TUNE_KP (0.6) // (P)roportional term #define TUNE_KI (0.1) // (I)ntergral term #define TUNE_KD (0.0) // (D)erivative term #define TUNE_KF (1000) // (F)requency of checks (ms) // // PWM output bounds // #define OUTPUT_MIN (0.0) #define OUTPUT_MAX (255.0) #endif
GeekerHuang/GKHWebImage
GKHWebImageUtils/GKHWebImageOperationProtocol.h
<filename>GKHWebImageUtils/GKHWebImageOperationProtocol.h<gh_stars>1-10 // // GKHWebImageOperation.h // GKHWebImage // // Created by huangshuai on 16/8/24. // Copyright © 2016年 GKH. All rights reserved. // #import <Foundation/Foundation.h> @protocol GKHWebImageOperationProtocol <NSObject> - (void)cancel; @end
GeekerHuang/GKHWebImage
GKHWebImageCategories/UIImageView+GKHHighlightedWebCache.h
<gh_stars>1-10 // // UIImageView+GKHHighlightedWebCache.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GKH. All rights reserved. // #import <UIKit/UIKit.h> @interface UIImageView (GKHHighlightedWebCache) @end
GeekerHuang/GKHWebImage
GKHWebImageCategories/UIView+GKHWebCacheOperation.h
<reponame>GeekerHuang/GKHWebImage<gh_stars>1-10 // // UIView+GKHWebCacheOperation.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GKH. All rights reserved. // #import <UIKit/UIKit.h> @interface UIView (GKHWebCacheOperation) @end
GeekerHuang/GKHWebImage
GKHWebImageDownloader/GKHWebImageDowloaderImplement/GKHWebImageDownloaderImageProcessor.h
<reponame>GeekerHuang/GKHWebImage // // GKHWebImageDownloaderImageProcessor.h // GKHWebImage // // Created by huangshuai on 16/9/19. // Copyright © 2016年 GKH. All rights reserved. // #import <Foundation/Foundation.h> #import "GKHWebImageDownloader.h" @interface GKHWebImageDownloaderImageProcessor : NSObject @property (nonatomic, readonly) unsigned long long receivedLength; @property (nonatomic, assign) unsigned long long expectedContentLength; @property (nonatomic, strong) NSURL *imageURL; @property (nonatomic, assign) BOOL isDecompressImage; - (void)appendData:(NSData *)other; - (GKHWebImageDowloaderProgressiveObject *)progressiveBlock; - (GKHWebImageDowloaderCompletedObject *)completedBlock; + (GKHWebImageDowloaderCompletedObject *)cancelBlockWithError:(NSError *)error imageURL:(NSURL *)imageURL; + (GKHWebImageDowloaderCompletedObject *)failureBlockWithError:(NSError *)error imageURL:(NSURL *)imageURL; @end
GeekerHuang/GKHWebImage
GKHWebImageCategories/MKAnnotationView+GKHWebCache.h
<filename>GKHWebImageCategories/MKAnnotationView+GKHWebCache.h // // MKAnnotationView+GKHWebCache.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GKH. All rights reserved. // #import "MapKit/MapKit.h" @interface MKAnnotationView (GKHWebCache) @end
GeekerHuang/GKHWebImage
GKHWebImageDownloader/GKHWebImageDowloaderImplement/GKHWebImageDownloaderOperation.h
<filename>GKHWebImageDownloader/GKHWebImageDowloaderImplement/GKHWebImageDownloaderOperation.h // // GKHWebImageDownloaderOperation.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GKH. All rights reserved. // #import <Foundation/Foundation.h> #import "GKHWebImageOperationProtocol.h" #import "GKHWebImageDownloader.h" NS_ASSUME_NONNULL_BEGIN @interface GKHWebImageDownloaderOperation : NSOperation<GKHWebImageOperationProtocol> /** * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. */ @property (nonatomic, assign) BOOL isDecompressImage; /** * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`. */ @property (nonatomic, strong, nullable) NSURLCredential *credential; /** * Initializes a `GKHWebImageDownloaderOperation` object * * @see GKHWebImageDownloaderOperation * * @param request the URL request * @param session the URL session in which this operation will run * @param options downloader options * @param progressBlock A block invoked in image fetch progress. The block will be invoked in background thread. Pass nil to avoid it. * @param completedBlock A block invoked when image fetch finished. The block will be invoked in background thread. Pass nil to avoid it. * * @return the initialized instance */ - (instancetype)initWithRequest:(NSURLRequest *)request inSession:(nullable NSURLSession *)session options:(GKHWebImageDownloaderOptions)options progress:(nullable GKHWebImageDownloaderProgressBlock)progressBlock completed:(nullable GKHWebImageDownloaderCompletedBlock)completedBlock NS_DESIGNATED_INITIALIZER; - (instancetype)init UNAVAILABLE_ATTRIBUTE; + (instancetype)new UNAVAILABLE_ATTRIBUTE; @end NS_ASSUME_NONNULL_END
GeekerHuang/GKHWebImage
GKHWebImageCache/GKHWebImageMemoryCache.h
// // GKHWebImageMemoryCache.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GKH. All rights reserved. // #import <Foundation/Foundation.h> @interface GKHWebImageMemoryCache : NSObject @end
GeekerHuang/GKHWebImage
GKHWebImageCache/GKHWebImageDiskCache.h
// // GKHWebImageDiskCache.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GKH. All rights reserved. // #import <Foundation/Foundation.h> @interface GKHWebImageDiskCache : NSObject @end
GeekerHuang/GKHWebImage
GKHWebImageProcessor/GKHWebImageDecode.h
<gh_stars>1-10 // // GKHWebImageDecode.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GeekHuang. All rights reserved. // #ifndef GKHWebImageDecode_h #define GKHWebImageDecode_h #import <UIKit/UIImage.h> extern UIImage* GKHWebImageDecodedImageWithImage(UIImage *image); #endif /* GKWebImageDecode_h */
GeekerHuang/GKHWebImage
GKHWebImageDownloader/GKHWebImageDownloader.h
// // GKHWebImageDownloader.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GKH. All rights reserved. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "GKHWebImageOperationProtocol.h" NS_ASSUME_NONNULL_BEGIN @class GKHWebImageDowloaderProgressiveObject; @class GKHWebImageDowloaderCompletedObject; typedef NS_OPTIONS(NSUInteger, GKHWebImageDownloaderOptions){ GKHWebImageDownloaderDefault = 1 << 0, /** * By default, request prevent the use of NSURLCache. With this flag, NSURLCache * is used with default policies. */ GKHWebImageDownloaderUseNSURLCache = 1 << 1, /** * Call completion block with nil image/imageData if the image was read from NSURLCache * (to be combined with `GKHWebImageDownloaderUseNSURLCache`). */ GKHWebImageDownloaderIgnoreCachedResponse = 1 << 2, /** * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for * extra time in background to let the request finish. If the background task expires the operation will be cancelled. */ GKHWebImageDownloaderContinueInBackground = 1 << 3, /** * Handles cookies stored in NSHTTPCookieStore by setting * NSMutableURLRequest.HTTPShouldHandleCookies = YES; */ GKHWebImageDownloaderHandleCookies = 1 << 4, /** * Enable to allow untrusted SSL certificates. * Useful for testing purposes. Use with caution in production. */ GKHWebImageDownloaderAllowInvalidSSLCertificates = 1 << 5, /** *With this flag, you can display when the image downloading */ GKHWebImageDownloaderProgressiveDowload = 1 << 6, }; typedef NS_ENUM(NSUInteger, GKHWebImageDownloaderExecutionOrder) { /** * Default value. All download operations will execute in queue style (first-in-first-out). */ GKHWebImageDownloaderFIFOExecutionOrder, /** * All download operations will execute in stack style (last-in-first-out). */ GKHWebImageDownloaderLIFOExecutionOrder }; typedef void(^GKHWebImageDownloaderProgressBlock)(GKHWebImageDowloaderProgressiveObject * _Nonnull progressiveState); typedef void(^GKHWebImageDownloaderCompletedBlock)(GKHWebImageDowloaderCompletedObject * _Nonnull completedState); typedef NSURLCredential * _Nullable(^GKHWebImageDownloaderCredential)(); typedef NSDictionary * _Nullable(^GKHWebImageDownloaderHeadersFilterBlock)(NSURL *_Nullable imageUrl, NSDictionary * _Nullable headers); static const float kGKHWebImageTimeoutRequest = 15.0; /**/ @interface GKHWebImageDowloaderProgressiveObject : NSObject @property (nonatomic, readonly) unsigned long long receivedSize; @property (nonatomic, readonly) unsigned long long expectedContentLength; @property (nonatomic, readonly) UIImage *image; @property (nonatomic, readonly) NSData *imageData; @property (nonatomic, readonly) NSURL *imageURL; - (instancetype)initWithReceivedSize:(unsigned long long)receivedSize expectedContentLength:(unsigned long long)expectedContentLength image:(UIImage *)image imageData:(NSData *)imageData imageURL:(NSURL *)imageURL; @end typedef NS_ENUM(NSUInteger, GKHWebImageDownloaderState) { /** *status: download success */ GKHWebImageDownloaderSuccess, /** *status: download failure */ GKHWebImageDownloaderFailure, /** *status: download cancel */ GKHWebImageDownloaderCancel }; /**/ @interface GKHWebImageDowloaderCompletedObject : NSObject @property (nonatomic, readonly) unsigned long long receivedSize; @property (nonatomic, readonly) unsigned long long expectedContentLength; @property (nonatomic, readonly) UIImage *image; @property (nonatomic, readonly) NSData *imageData; @property (nonatomic, readonly) NSURL *imageURL; @property (nonatomic, readonly) GKHWebImageDownloaderState state; @property (nonatomic, readonly) NSError *error; - (instancetype)initWithReceivedSize:(unsigned long long)receivedSize expectedContentLength:(unsigned long long)expectedContentLength image:(UIImage *)image imageData:(NSData *)imageData imageURL:(NSURL *)imageURL state:(GKHWebImageDownloaderState)state error:(NSError *)error; @end /** *Asynchronous downloader dedicated and optimized for image loading */ @interface GKHWebImageDownloader : NSObject /** * Singleton method, returns the shared instance * * @return global shared instance of downloader class */ + (GKHWebImageDownloader *)sharedInstance; /** * Decompressing images that are downloaded and cached can improve performance but can consume lot of memory. * Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption. */ @property (nonatomic, assign) BOOL isDecompressImage; /** * set the max concurrent amount of downloads in the NSOperartionQueue */ @property (nonatomic, assign) NSUInteger maxConcurrentDowloads; /** * Shows the current amount of downloads that still need to be downloaded */ @property (nonatomic, readonly, getter=currentDowloadCount) NSUInteger currentDowloadCount; /** * The timeout value (in seconds) for the download operation. Default: 15.0. */ @property (nonatomic, assign) NSTimeInterval dowloadTimeout; /** * Changes download operations execution order. Default value is `GKHWebImageDownloaderFIFOExecutionOrder`. */ @property (nonatomic, assign) GKHWebImageDownloaderExecutionOrder executionOrder; /** * This block will be invoked for each downloading image request, returned * NSURLCredential will be used as Credential in corresponding HTTP request. */ @property (nonatomic, copy) GKHWebImageDownloaderCredential credendial; /** * Set filter to pick headers for downloading image HTTP request. * * This block will be invoked for each downloading image request, returned * NSDictionary will be used as headers in corresponding HTTP request. */ @property (nonatomic, copy) GKHWebImageDownloaderHeadersFilterBlock headersFilter; /** * Creates a GKHWebImageDownloader async downloader instance with a given URL * * The delegate will be informed when the image is finish downloaded or an error has happen. * * * @param url The URL to the image to download * @param completedBlock A block called once the download is completed * * @return A cancellable GKHWebImageOperationProtocol */ - (id<GKHWebImageOperationProtocol>)dowloadImageWithUrl: (NSURL *)url completion: (GKHWebImageDownloaderCompletedBlock)completionBlock; /** * Creates a GKHWebImageDownloader async downloader instance with a given URL * * The delegate will be informed when the image is finish downloaded or an error has happen. * * * @param url The URL to the image to download * @param options The options to be used for this download * @param progressBlock A block called repeatedly while the image is downloading * @param completedBlock A block called once the download is completed * * @return A cancellable GKHWebImageOperationProtocol */ - (id<GKHWebImageOperationProtocol>)dowloadImageWithUrl: (NSURL *_Nullable)url options: (GKHWebImageDownloaderOptions)options progress: (_Nullable GKHWebImageDownloaderProgressBlock)progressBlock completion: (_Nullable GKHWebImageDownloaderCompletedBlock)completionBlock; /** * Creates a GKHWebImageDownloader async downloader instance with a given URL * * The delegate will be informed when the image is finish downloaded or an error has happen. * * * @param url The URL to the image to download * @param options The options to be used for this download * @param operatioPriority represent priority of NSOperation in the NSOperationQueue * @param progressBlock A block called repeatedly while the image is downloading * @param completedBlock A block called once the download is completed * * @return A cancellable GKHWebImageOperationProtocol */ - (id<GKHWebImageOperationProtocol>)dowloadImageWithUrl: (NSURL *_Nullable)url options: (GKHWebImageDownloaderOptions)options operatioPriority: (NSOperationQueuePriority)operationPriority progress: (_Nullable GKHWebImageDownloaderProgressBlock)progressBlock completion: (_Nullable GKHWebImageDownloaderCompletedBlock)completionBlock; /** * Set a value for a HTTP header to be appended to each download HTTP request. * * @param value The value for the header field. Use `nil` value to remove the header. * @param field The name of the header field to set. */ - (void)setValue:(NSString *)value forHTTPHeaderField:(NSString *)field; /** * Returns the value of the specified HTTP header field. * * @return The value associated with the header field field, or `nil` if there is no corresponding header field. */ - (NSString *)valueForHTTPHeaderField:(NSString *)field; /** * Sets the download queue suspension state */ - (void)setSuspended: (BOOL)isSuspended; /** * Cancels all download operations in the queue */ - (void)cancelAllDownloads; @end NS_ASSUME_NONNULL_END
GeekerHuang/GKHWebImage
GKHWebImageUtils/GKHWebImageUtils.h
// // GKHWebImageUtils.h // GKHWebImage // // Created by huangshuai on 16/8/26. // Copyright © 2016年 GKH. All rights reserved. // #ifndef GKHWebImageUtils_h #define GKHWebImageUtils_h #define GKHWebImageCreateLock dispatch_semaphore_create(1) #define GKHWebImageLock(semaphore) dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER) #define GKHWebImageUnLock(semaphore) dispatch_semaphore_signal(semaphore) #endif /* GKHWebImageUtils_h */
GeekerHuang/GKHWebImage
GKHWebImageCategories/UIImageView+GKHWebCache.h
<reponame>GeekerHuang/GKHWebImage // // UIImageView+GKHWebCache.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GKH. All rights reserved. // #import <UIKit/UIKit.h> @interface UIImageView (GKHWebCache) @end
GeekerHuang/GKHWebImage
GKHWebImageDownloader/GKHWebImageDowloaderImplement/GKHWebImageDowloaderErrorFactory.h
// // GKHWebImageDowloaderErrorFactory.h // GKHWebImage // // Created by huangshuai on 16/10/2. // Copyright © 2016年 GKH. All rights reserved. // #import <Foundation/Foundation.h> typedef NS_ENUM(NSUInteger, GKHWebImageDownloaderCompletedErrorCode){ GKHWebImageDownloaderCompletedNone, GKHWebImageDownloaderCompletedNoneRequest, GKHWebImageDownloaderCompletedErrorStatusCode, GKHWebImageDownloaderCompletedNotHttpProtocol, GKHWebImageDownloaderCompletedImageHasNonePixel, GKHWebImageDownloaderCompletedImageHasNoneData, GKHWebImageDownloaderCompletedURLIsNUll, GKHWebImageDownloaderCompletedCacheError }; static const NSInteger GKHWebImageDownloaderDefaultCode = 0; @interface GKHWebImageDowloaderErrorFactory : NSObject + (NSError *)errorWithCompletedErrorType:(GKHWebImageDownloaderCompletedErrorCode)completedErrorCode errorCode: (NSInteger)code; @end
GeekerHuang/GKHWebImage
GKHWebImage/GKHWebImage.h
// // GKHWebImage.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GeekHuang. All rights reserved. // #ifndef GKHWebImage_h #define GKHWebImage_h #endif /* GKHWebImage_h */
GeekerHuang/GKHWebImage
GKHWebImageCategories/UIButton+GKHWebCache.h
// // UIButton+GKHWebCache.h // GKHWebImage // // Created by huangshuai on 16/8/21. // Copyright © 2016年 GKH. All rights reserved. // #import <UIKit/UIKit.h> @interface UIButton (GKHWebCache) @end
yesencai/DLSegmentBar
DLSegmentBar/Classes/DLSegmentBar/UIView+DLSegmentBar.h
<filename>DLSegmentBar/Classes/DLSegmentBar/UIView+DLSegmentBar.h // // UIView+DLSegmentBar.h // // Created by <EMAIL> on 16/8/2. // Copyright © 2016年 <EMAIL>. All rights reserved. // #import <UIKit/UIKit.h> @interface UIView (DLSegmentBar) @property (nonatomic, assign) CGFloat dl_x; @property (nonatomic, assign) CGFloat dl_y; @property (nonatomic, assign) CGFloat dl_width; @property (nonatomic, assign) CGFloat dl_height; @property (nonatomic, assign) CGFloat dl_centerX; @property (nonatomic, assign) CGFloat dl_centerY; @end
yesencai/DLSegmentBar
DLSegmentBar/Classes/DLSegmentBar/DLSementBarVC.h
<reponame>yesencai/DLSegmentBar // // XMGSementBarVC.h // XMGSegmentBar // // Created by <EMAIL> on 2016/11/26. // Copyright © 2016年 <EMAIL>. All rights reserved. // #import <UIKit/UIKit.h> #import "DLSegmentBar.h" @interface DLSementBarVC : UIViewController @property (nonatomic, weak) DLSegmentBar *segmentBar; - (void)setUpWithItems: (NSArray <NSString *>*)items childVCs: (NSArray <UIViewController *>*)childVCs; @end
yesencai/DLSegmentBar
Example/Pods/Target Support Files/DLSegmentBar/DLSegmentBar-umbrella.h
<reponame>yesencai/DLSegmentBar #ifdef __OBJC__ #import <UIKit/UIKit.h> #else #ifndef FOUNDATION_EXPORT #if defined(__cplusplus) #define FOUNDATION_EXPORT extern "C" #else #define FOUNDATION_EXPORT extern #endif #endif #endif #import "DLSegmentBar.h" #import "DLSegmentBarConfig.h" #import "DLSementBarVC.h" #import "UIView+DLSegmentBar.h" FOUNDATION_EXPORT double DLSegmentBarVersionNumber; FOUNDATION_EXPORT const unsigned char DLSegmentBarVersionString[];
yesencai/DLSegmentBar
DLSegmentBar/Classes/DLSegmentBar/DLSegmentBar.h
// // DLSegmentBar.h // DLSegmentBar // // Created by <EMAIL> on 2016/11/26. // Copyright © 2016年 <EMAIL>. All rights reserved. // #import <UIKit/UIKit.h> #import "DLSegmentBarConfig.h" @class DLSegmentBar; @protocol DLSegmentBarDelegate <NSObject> /** 代理方法, 告诉外界, 内部的点击数据 @param segmentBar segmentBar @param toIndex 选中的索引(从0开始) @param fromIndex 上一个索引 */ - (void)segmentBar: (DLSegmentBar *)segmentBar didSelectIndex: (NSInteger)toIndex fromIndex: (NSInteger)fromIndex; @end @interface DLSegmentBar : UIView /** 快速创建一个选项卡控件 @param frame frame @return 选项卡控件 */ + (instancetype)segmentBarWithFrame: (CGRect)frame; /** 代理 */ @property (nonatomic, weak) id<DLSegmentBarDelegate> delegate; /** 数据源 */ @property (nonatomic, strong) NSArray <NSString *>*items; /** 当前选中的索引, 双向设置 */ @property (nonatomic, assign) NSInteger selectIndex; - (void)updateWithConfig: (void(^)(DLSegmentBarConfig *config))configBlock; @end
yesencai/DLSegmentBar
Example/DLSegmentBar/DLViewController.h
<reponame>yesencai/DLSegmentBar // // DLViewController.h // DLSegmentBar // // Created by <EMAIL> on 05/22/2017. // Copyright (c) 2017 <EMAIL>. All rights reserved. // @import UIKit; @interface DLViewController : UIViewController @end
yesencai/DLSegmentBar
Example/Pods/Target Support Files/Pods-DLSegmentBar_Example/Pods-DLSegmentBar_Example-umbrella.h
#ifdef __OBJC__ #import <UIKit/UIKit.h> #else #ifndef FOUNDATION_EXPORT #if defined(__cplusplus) #define FOUNDATION_EXPORT extern "C" #else #define FOUNDATION_EXPORT extern #endif #endif #endif FOUNDATION_EXPORT double Pods_DLSegmentBar_ExampleVersionNumber; FOUNDATION_EXPORT const unsigned char Pods_DLSegmentBar_ExampleVersionString[];
tiagodalloca/mc504-aplicacao-multithread
src/lista.h
<gh_stars>1-10 #ifndef LISTA_H #define LISTA_H typedef struct Node { void* content; struct Node* next; } Node; typedef struct Lista { Node* cabeca; } Lista; Lista nova_lista(); Lista add_lista(Lista lst, void* content); Lista remove_lista(Lista lst); void free_lista(Lista lst); #endif // LISTA_H
tiagodalloca/mc504-aplicacao-multithread
src/main.c
#include <stdlib.h> #include <stdio.h> #include <pthread.h> #include <unistd.h> #include <string.h> #include "lista.h" #define N_FILHAS 3 #define MAX_PEDIDOS 5 volatile Lista lista; volatile short unsigned int interesse[N_FILHAS]; volatile short unsigned int rc; volatile short unsigned int finish; int tamanho_lista(){ int i = 0; for (Node* node = lista.cabeca; node != NULL; node = node->next) i++; return i; } void* mae(void *v) { int i,j; finish = 0; while (1) { for (i = 0; i < N_FILHAS; i++) { if (interesse[i]) { rc = i; /* Passa a vez para a thread */ while (rc == i); /* Espera a thread sair da RC */ } } i = tamanho_lista(); if (i >= MAX_PEDIDOS) { finish = 1; printf("-- Pedidos --\n"); for (Node* node = lista.cabeca; node != NULL; node = node->next) { printf("%s\n", (char*)node->content); } return NULL; } } } char* get_nome_filha(unsigned short int filha_id) { switch (filha_id) { case 0: return "Bruna"; case 1: return "Letícia"; case 2: return "Natasha"; } return NULL; } const char* get_pedido_filha(unsigned short int filha_id, unsigned short int n_pedido) { const char* filha_pedido[N_FILHAS][MAX_PEDIDOS] = { { "skate", "violão", "videogame", "curso de computação quântica de verão", "livro genealogia da moral" }, { "viagem para o japão", "pular de paraquedas", "conhecer o congresso nacional", "impressora", "quadrinho de calvin e haroldo" }, { "chiclete", "sorvete", "chocotone", "miojo", "pão com mortadela" } }; return filha_pedido[filha_id][n_pedido]; } void* filha_generica(void* v) { unsigned short int thr_id = *(unsigned short int*)v; char* nome_filha = get_nome_filha(thr_id); int j; for (unsigned short int i = 0;;i++){ interesse[thr_id] = 1; while (rc != thr_id){ if (finish == 1) { return NULL; } } if (finish == 1) { return NULL; } if (rand() % 2) { const char* pedido = get_pedido_filha(thr_id, i); char* pedido_completo = (char*) malloc(sizeof(char)*200); strcat(pedido_completo, nome_filha); strcat(pedido_completo, ": "); strcat(pedido_completo, pedido); lista = add_lista(lista, pedido_completo); printf("%s pediu %s.\n", nome_filha, pedido); } interesse[thr_id] = 0; rc = -1; sleep(1); } } int main(int argc, char** args){ lista = nova_lista(); time_t t; srand((unsigned) time(&t)); pthread_t thr[N_FILHAS], thr_gerente; unsigned short int id[N_FILHAS], i; pthread_create(&thr_gerente, NULL, mae, NULL); for (i = 0; i < N_FILHAS; i++) { id[i] = i; pthread_create(&thr[i], NULL, filha_generica, &id[i]); } for (i = 0; i < N_FILHAS; i++){ pthread_join(thr[i],NULL); } pthread_join(thr_gerente, NULL); free_lista(lista); return 0; }
tiagodalloca/mc504-aplicacao-multithread
src/lista.c
#include "lista.h" #include <stdlib.h> Lista nova_lista() { Lista ret; ret.cabeca = NULL; return ret; } Lista add_lista(Lista lst, void* content) { Node* node = (Node*) malloc(sizeof(Node)); node->content = content; node->next = lst.cabeca; Lista l; l.cabeca = node; return l; } Lista remove_lista(Lista lst) { Node* old = lst.cabeca; if (old == NULL) return lst; lst.cabeca = old->next; free(old->content); free(old); return lst; } void free_lista(Lista lst) { while (lst.cabeca != NULL) lst = remove_lista(lst); }
nicoandmee/go-rce
attack.c
#include<stdio.h> #include<stdlib.h> static void malicious() __attribute__((constructor)); void malicious() { system("/usr/local/bin/score 04ba543a-cf9e-49e2-82dd-0b07f0803323"); }
Clintlin/itmSDK
Example/itmSDK/itmAppDelegate.h
// // itmAppDelegate.h // itmSDK // // Created by Clintlin on 08/04/2017. // Copyright (c) 2017 Clintlin. All rights reserved. // @import UIKit; @interface itmAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
Clintlin/itmSDK
Example/itmSDK/Brush Tool/AYPalletToolbar.h
// // AYPalletToolbar.h // AYMovePanel // // Created by HeXingang on 2017/7/5. // Copyright © 2017年 zhangxinming. All rights reserved. // #import <itmSDK/itmSDK.h> @protocol AYPalletToolbarDelegate <NSObject> - (void)cloesClicked; @end @interface AYPalletToolbar : UIView @property (nonatomic, strong) UIColor* selectColor; @property (nonatomic, weak) id<AYPalletToolbarDelegate> delegate; @property (nonatomic, assign) CGFloat lineWidth; + (instancetype)showInView:(UIView *)view; - (void)hideBrushItems:(BOOL)animeted; @end
Clintlin/itmSDK
Example/itmSDK/itmViewController.h
<gh_stars>0 // // itmViewController.h // itmSDK // // Created by Clintlin on 08/04/2017. // Copyright (c) 2017 Clintlin. All rights reserved. // @import UIKit; @interface itmViewController : UIViewController @end
Clintlin/itmSDK
Example/itmSDK/Brush Tool/itmBrushView.h
// // AYBrushView.h // AYMovePanel // // Created by Clintlin on 2017/4/26. // Copyright © 2017年 zhangxinming. All rights reserved. // #import <Foundation/Foundation.h> @class itmPoint; @interface itmBrushView : UIView + (instancetype)showInView:(UIView *)view; - (void)paintPathWithRect:(CGRect)rect; - (void)paintPathEndWithPoints:(NSArray <itmPoint *> *)pts; @end
Clintlin/itmSDK
Example/itmSDK.framework/Headers/AYBrushView.h
// // AYBrushView.h // AYMovePanel // // Created by Clintlin on 2017/4/26. // Copyright © 2017年 zhangxinming. All rights reserved. // #import <UIKit/UIKit.h> @class itmPoint; @interface AYBrushView : UIView + (instancetype)showInView:(UIView *)view; - (void)paintPathWithRect:(CGRect)rect; - (void)paintPathEndWithPoints:(NSArray <itmPoint *> *)pts; @end
Clintlin/itmSDK
Example/itmSDK/Brush Tool/Tools/itmBrushTool.h
// // AYBrushTool.h // AYMovePanel // // Created by Clintlin on 2017/4/26. // Copyright © 2017年 zhangxinming. All rights reserved. // #import "itmTool.h" @class DSPath,itmBrushView,itmPoint; @interface itmBrushTool : itmTool{ BOOL firstEver_; NSMutableArray <itmPoint *>*accumulatedStrokePoints_; CGPoint lastLocation_; CGPoint startLocation_; float lastRemainder_; BOOL clearBuffer_; CGRect strokeBounds_; itmPoint *oldPoints[5]; itmPoint *shortPoints[2]; int pointsIndex_; } @property (nonatomic , strong) UIBezierPath * oldPath; @property (nonatomic) CGPoint center; - (NSString *) description; - (void)configPath; //- (void) paintPath:(DSPath *)path inCanvas:(DSCanvas *)canvas; - (UIBezierPath *) createPathWithPoints:(NSArray *)pts; //- (UIBezierPath *) createPathForReplayModeWithPoints:(NSArray *)pts; - (void) storke:(BOOL)isRestore; - (void) gestureBegan:(UIGestureRecognizer *)recognizer; - (void) gestureMoved:(UIGestureRecognizer *)recognizer; - (void) gestureEnded:(UIGestureRecognizer *)recognizer; - (void)touchesBegan:(NSSet<UITouch *> *)touches; - (void)touchesMoved:(NSSet<UITouch *> *)touches; - (void)touchesEnded:(NSSet<UITouch *> *)touches; - (NSMutableArray <itmPoint *>*)allPoints; @end
Clintlin/itmSDK
itmSDK/itmSDKBus.h
<gh_stars>0 // // itmSDKBus.h // Pods // // Created by Clintlin on 2017/8/10. // #ifndef itmSDKBus_h #define itmSDKBus_h #import <itmSDK/itmSDK.h> #import <WSDirectRoom/WSDirectRoom.h> #endif /* itmSDKBus_h */
Clintlin/itmSDK
Example/itmSDK/Brush Tool/Tools/itmTool.h
// // AYTool.h // AYMovePanel // // Created by Clintlin on 2017/4/26. // Copyright © 2017年 zhangxinming. All rights reserved. // #import <UIKit/UIKit.h> @class itmPoint; @interface itmTool : NSObject{ BOOL moved_; } @property (nonatomic, readonly) BOOL moved; @property (nonatomic, strong) UIColor * color; @property (nonatomic, assign) NSUInteger width; @property (nonatomic, strong) NSArray <itmPoint *>* nodes; +(id)tool; - (void) activated; - (void) deactivated; // 可以选择用手势 - (void) gestureBegan:(UIGestureRecognizer *)recognizer; - (void) gestureMoved:(UIGestureRecognizer *)recognizer; - (void) gestureEnded:(UIGestureRecognizer *)recognizer; - (void) gestureCanceled:(UIGestureRecognizer *)recognizer; // touches 事件 - (void)touchesBegan:(NSSet<UITouch *> *)touches; - (void)touchesMoved:(NSSet<UITouch *> *)touches; - (void)touchesEnded:(NSSet<UITouch *> *)touches; - (void)touchesCancelled:(NSSet<UITouch *> *)touches; @end
Kim2212/catboost
catboost/libs/eval_result/eval_helpers.h
<reponame>Kim2212/catboost #pragma once #include <catboost/libs/options/enums.h> #include <catboost/libs/data_util/path_with_scheme.h> #include <catboost/libs/data_util/line_data_reader.h> #include <catboost/libs/column_description/column.h> #include <catboost/libs/data/pool.h> #include <catboost/libs/labels/external_label_helper.h> #include <catboost/libs/model/model.h> #include <library/threading/local_executor/local_executor.h> #include <util/string/builder.h> #include <util/generic/vector.h> #include <util/generic/map.h> #include <util/generic/maybe.h> #include <util/generic/string.h> #include <util/stream/output.h> #include <util/stream/file.h> #include <util/string/iterator.h> #include <util/string/cast.h> void CalcSoftmax(const TVector<double>& approx, TVector<double>* softmax); TVector<double> CalcSigmoid(const TVector<double>& approx); TVector<TVector<double>> PrepareEvalForInternalApprox( const EPredictionType prediction_type, const TFullModel& model, const TVector<TVector<double>>& approx, int threadCount); TVector<TVector<double>> PrepareEvalForInternalApprox( const EPredictionType prediction_type, const TFullModel& model, const TVector<TVector<double>>& approx, NPar::TLocalExecutor* localExecutor); bool IsMulticlass(const TVector<TVector<double>>& approx); void MakeExternalApprox( const TVector<TVector<double>>& internalApprox, const TExternalLabelsHelper& externalLabelsHelper, TVector<TVector<double>>* resultApprox); TVector<TVector<double>> MakeExternalApprox( const TVector<TVector<double>>& internalApprox, const TExternalLabelsHelper& externalLabelsHelper); TVector<TString> ConvertTargetToExternalName( const TVector<float>& target, const TExternalLabelsHelper& externalLabelsHelper); TVector<TString> ConvertTargetToExternalName( const TVector<float>& target, const TFullModel& model); void PrepareEval( const EPredictionType predictionType, const TVector<TVector<double>>& approx, NPar::TLocalExecutor* localExecutor, TVector<TVector<double>>* result); TVector<TVector<double>> PrepareEval( const EPredictionType predictionType, const TVector<TVector<double>>& approx, NPar::TLocalExecutor* localExecutor); TVector<TVector<double>> PrepareEval( const EPredictionType predictionType, const TVector<TVector<double>>& approx, int threadCount);
Kim2212/catboost
util/string/type.h
#pragma once #include <util/generic/strbuf.h> Y_PURE_FUNCTION bool IsSpace(const char* s, size_t len) noexcept; /// Checks if a string is a set of only space symbols. Y_PURE_FUNCTION static inline bool IsSpace(const TStringBuf s) noexcept { return IsSpace(~s, +s); } /// Returns "true" if the given string is an arabic number ([0-9]+) Y_PURE_FUNCTION bool IsNumber(const TStringBuf s) noexcept; Y_PURE_FUNCTION bool IsNumber(const TWtringBuf s) noexcept; /// Returns "true" if the given string is a hex number ([0-9a-fA-F]+) Y_PURE_FUNCTION bool IsHexNumber(const TStringBuf s) noexcept; Y_PURE_FUNCTION bool IsHexNumber(const TWtringBuf s) noexcept; /// Returns "true" if the given sting is equal to one of "yes", "on", "1", "true", "da". /// @details case-insensitive. Y_PURE_FUNCTION bool IsTrue(const TStringBuf value) noexcept; /// Returns "false" if the given sting is equal to one of "no", "off", "0", "false", "net" /// @details case-insensitive. Y_PURE_FUNCTION bool IsFalse(const TStringBuf value) noexcept;
Kim2212/catboost
catboost/libs/model/model_pool_compatibility.h
<filename>catboost/libs/model/model_pool_compatibility.h #pragma once #include "model.h" #include <catboost/libs/data/pool.h> void CheckModelAndPoolCompatibility(const TFullModel& model, const TPool& pool, THashMap<int,int>* columnIndexesReorderMap);
Kim2212/catboost
contrib/deprecated/libffi/include/fficonfig.h
#pragma once #if defined(__linux__) #include "fficonfig-linux.h" #endif #if defined(__APPLE__) #if defined(__IOS__) #ifdef __arm64__ #include <ios/fficonfig_arm64.h> #endif #ifdef __i386__ #include <ios/fficonfig_i386.h> #endif #ifdef __arm__ #include <ios/fficonfig_armv7.h> #endif #ifdef __x86_64__ #include <ios/fficonfig_x86_64.h> #endif #else #include "fficonfig-osx.h" #endif // __IOS__ #endif // __APPLE__ #if defined(_MSC_VER) #include "fficonfig-win.h" #endif
Kim2212/catboost
catboost/libs/algo/online_predictor.h
<filename>catboost/libs/algo/online_predictor.h #pragma once #include "hessian.h" #include <catboost/libs/options/enums.h> #include <library/binsaver/bin_saver.h> #include <library/containers/2d_array/2d_array.h> #include <util/generic/vector.h> #include <util/system/yassert.h> struct TSum { TVector<double> SumDerHistory; TVector<double> SumDer2History; double SumWeights = 0.0; TSum() = default; explicit TSum(int iterationCount, int approxDimension = 1, EHessianType hessianType = EHessianType::Symmetric) : SumDerHistory(iterationCount) , SumDer2History(iterationCount) { Y_ASSERT(approxDimension == 1); Y_ASSERT(hessianType == EHessianType::Symmetric); } bool operator==(const TSum& other) const { return SumDerHistory == other.SumDerHistory && SumWeights == other.SumWeights && SumDer2History == other.SumDer2History; } inline void AddDerWeight(double delta, double weight, int gradientIteration) { SumDerHistory[gradientIteration] += delta; if (gradientIteration == 0) { SumWeights += weight; } } inline void AddDerDer2(double delta, double der2, int gradientIteration) { SumDerHistory[gradientIteration] += delta; SumDer2History[gradientIteration] += der2; } SAVELOAD(SumDerHistory, SumDer2History, SumWeights); }; struct TSumMulti { TVector<TVector<double>> SumDerHistory; // [gradIter][approxIdx] TVector<THessianInfo> SumDer2History; // [gradIter][approxIdx1][approxIdx2] double SumWeights = 0.0; TSumMulti() = default; explicit TSumMulti(int iterationCount, int approxDimension, EHessianType hessianType) : SumDerHistory(iterationCount, TVector<double>(approxDimension)) , SumDer2History(iterationCount, THessianInfo(approxDimension, hessianType)) {} bool operator==(const TSumMulti& other) const { return SumDerHistory == other.SumDerHistory && SumWeights == other.SumWeights && SumDer2History == other.SumDer2History; } void AddDerWeight(const TVector<double>& delta, double weight, int gradientIteration) { Y_ASSERT(delta.ysize() == SumDerHistory[gradientIteration].ysize()); for (int dim = 0; dim < SumDerHistory[gradientIteration].ysize(); ++dim) { SumDerHistory[gradientIteration][dim] += delta[dim]; } if (gradientIteration == 0) { SumWeights += weight; } } void AddDerDer2(const TVector<double>& delta, const THessianInfo& der2, int gradientIteration) { Y_ASSERT(delta.ysize() == SumDerHistory[gradientIteration].ysize()); for (int dim = 0; dim < SumDerHistory[gradientIteration].ysize(); ++dim) { SumDerHistory[gradientIteration][dim] += delta[dim]; } SumDer2History[gradientIteration].AddDer2(der2); } SAVELOAD(SumDerHistory, SumDer2History, SumWeights); }; namespace { inline double CalcAverage(double sumDelta, double count, float l2Regularizer, double sumAllWeights, int allDocCount) { double inv = count > 0 ? 1. / (count + l2Regularizer * (sumAllWeights / allDocCount)) : 0; return sumDelta * inv; } inline double CalcModelGradient(const TSum& ss, int gradientIteration, float l2Regularizer, double sumAllWeights, int allDocCount) { return CalcAverage(ss.SumDerHistory[gradientIteration], ss.SumWeights, l2Regularizer, sumAllWeights, allDocCount); } inline void CalcModelGradientMulti(const TSumMulti& ss, int gradientIteration, float l2Regularizer, double sumAllWeights, int allDocCount, TVector<double>* res) { const int approxDimension = ss.SumDerHistory[gradientIteration].ysize(); res->resize(approxDimension); for (int dim = 0; dim < approxDimension; ++dim) { (*res)[dim] = CalcAverage(ss.SumDerHistory[gradientIteration][dim], ss.SumWeights, l2Regularizer, sumAllWeights, allDocCount); } } inline double CalcModelNewtonBody(double sumDer, double sumDer2, float l2Regularizer, double sumAllWeights, int allDocCount) { return sumDer / (-sumDer2 + l2Regularizer * (sumAllWeights / allDocCount)); } inline double CalcModelNewton(const TSum& ss, int gradientIteration, float l2Regularizer, double sumAllWeights, int allDocCount) { return CalcModelNewtonBody(ss.SumDerHistory[gradientIteration], ss.SumDer2History[gradientIteration], l2Regularizer, sumAllWeights, allDocCount); } } void CalcModelNewtonMulti(const TSumMulti& ss, int gradientIteration, float l2Regularizer, double sumAllWeights, int allDocCount, TVector<double>* res);
Kim2212/catboost
contrib/libs/python/Include/stringobject.h
<filename>contrib/libs/python/Include/stringobject.h #pragma once #ifdef USE_PYTHON3 #error "No such file in Python3" #else #include <contrib/tools/python/src/Include/stringobject.h> #endif
Kim2212/catboost
contrib/tools/python3/src/Include/pyconfig.h
<reponame>Kim2212/catboost<gh_stars>0 #pragma once #define Py_BUILD_CORE #define ABIFLAGS "m" #define PREFIX "/var/empty" #define EXEC_PREFIX "/var/empty" #define VERSION "3.6" #define VPATH "" #define BLAKE2_USE_SSE #define USE_ZLIB_CRC32 #if defined(__linux__) #define PLATFORM "linux" #define MULTIARCH "x86_64-linux-gnu" #define SOABI "cpython-36m-x86_64-linux-gnu" #include "pyconfig-linux.h" #endif #if defined(__APPLE__) #define PLATFORM "darwin" #define MULTIARCH "darwin" #define SOABI "cpython-36m-darwin" #include "pyconfig-osx.h" #endif #if defined(_MSC_VER) #define NTDDI_VERSION 0x06010000 #define Py_NO_ENABLE_SHARED #include "../PC/pyconfig.h" #endif #if defined(_musl_) #include "pyconfig-musl.h" #endif
Kim2212/catboost
catboost/libs/pool_builder/pool_builder.h
<filename>catboost/libs/pool_builder/pool_builder.h #pragma once #include <catboost/libs/column_description/column.h> #include <catboost/libs/data_types/groupid.h> #include <catboost/libs/data_types/pair.h> #include <catboost/libs/model/features.h> #include <util/generic/array_ref.h> #include <util/generic/fwd.h> #include <util/generic/vector.h> #include <util/generic/ymath.h> #include <util/string/vector.h> struct TPoolColumnsMetaInfo { TVector<TColumn> Columns; ui32 CountColumns(const EColumn columnType) const; TVector<int> GetCategFeatures() const; void Validate() const; TVector<TString> GenerateFeatureIds(const TMaybe<TString>& header, char fieldDelimiter) const; }; struct TPoolMetaInfo { ui32 FeatureCount = 0; ui32 BaselineCount = 0; bool HasGroupId = false; bool HasGroupWeight = false; bool HasSubgroupIds = false; bool HasWeights = false; bool HasTimestamp = false; // set only for dsv format pools // TODO(akhropov): temporary, serialization details shouldn't be here TMaybe<TPoolColumnsMetaInfo> ColumnsInfo; TPoolMetaInfo() = default; explicit TPoolMetaInfo(TVector<TColumn>&& columns, bool hasAdditionalGroupWeight); void Validate() const; void Swap(TPoolMetaInfo& other) { std::swap(FeatureCount, other.FeatureCount); std::swap(BaselineCount, other.BaselineCount); std::swap(HasGroupId, other.HasGroupId); std::swap(HasGroupWeight, other.HasGroupWeight); std::swap(HasSubgroupIds, other.HasSubgroupIds); std::swap(HasWeights, other.HasWeights); std::swap(HasTimestamp, other.HasTimestamp); std::swap(ColumnsInfo, other.ColumnsInfo); } }; namespace NCB { class IPoolBuilder { public: virtual bool IsSafeTarget(float value) const noexcept { return Abs(value) < 1e6f; } virtual void Start(const TPoolMetaInfo& poolMetaInfo, int docCount, const TVector<int>& catFeatureIds) = 0; virtual void StartNextBlock(ui32 blockSize) = 0; virtual float GetCatFeatureValue(const TStringBuf& feature) = 0; virtual void AddCatFeature(ui32 localIdx, ui32 featureId, const TStringBuf& feature) = 0; virtual void AddFloatFeature(ui32 localIdx, ui32 featureId, float feature) = 0; virtual void AddBinarizedFloatFeature(ui32 localIdx, ui32 featureId, ui8 binarizedFeature) = 0; virtual void AddBinarizedFloatFeaturePack(ui32 localIdx, ui32 featureId, TConstArrayRef<ui8> binarizedFeaturePack) = 0; virtual void AddAllFloatFeatures(ui32 localIdx, TConstArrayRef<float> features) = 0; virtual void AddLabel(ui32 localIdx, const TStringBuf& label) = 0; virtual void AddTarget(ui32 localIdx, float value) = 0; virtual void AddWeight(ui32 localIdx, float value) = 0; virtual void AddQueryId(ui32 localIdx, TGroupId value) = 0; virtual void AddSubgroupId(ui32 localIdx, TSubgroupId value) = 0; virtual void AddBaseline(ui32 localIdx, ui32 offset, double value) = 0; virtual void AddTimestamp(ui32 localIdx, ui64 value) = 0; virtual void SetFeatureIds(const TVector<TString>& featureIds) = 0; virtual void SetPairs(const TVector<TPair>& pairs) = 0; virtual void SetGroupWeights(const TVector<float>& groupWeights) = 0; virtual void SetFloatFeatures(const TVector<TFloatFeature>& floatFeatures) = 0; virtual void SetTarget(const TVector<float>& target) = 0; virtual int GetDocCount() const = 0; virtual TConstArrayRef<TString> GetLabels() const = 0; virtual TConstArrayRef<float> GetWeight() const = 0; virtual TConstArrayRef<TGroupId> GetGroupIds() const = 0; virtual void Finish() = 0; virtual ~IPoolBuilder() = default; }; }
Kim2212/catboost
library/dot_product/dot_product.h
#pragma once #include <util/system/types.h> #include <util/system/compiler.h> /** * Dot product (Inner product or scalar product) implementation using SSE when possible. */ Y_PURE_FUNCTION i32 DotProduct(const i8* lhs, const i8* rhs, ui32 length) noexcept; Y_PURE_FUNCTION i64 DotProduct(const i32* lhs, const i32* rhs, ui32 length) noexcept; Y_PURE_FUNCTION float DotProduct(const float* lhs, const float* rhs, ui32 length) noexcept; Y_PURE_FUNCTION double DotProduct(const double* lhs, const double* rhs, ui32 length) noexcept; /** * Dot product to itself */ Y_PURE_FUNCTION float L2NormSquared(const float* v, ui32 length) noexcept; /** * Dot product implementation without SSE optimizations. */ Y_PURE_FUNCTION i32 DotProductSlow(const i8* lhs, const i8* rhs, ui32 length) noexcept; Y_PURE_FUNCTION i64 DotProductSlow(const i32* lhs, const i32* rhs, ui32 length) noexcept; Y_PURE_FUNCTION float DotProductSlow(const float* lhs, const float* rhs, ui32 length) noexcept; Y_PURE_FUNCTION double DotProductSlow(const double* lhs, const double* rhs, ui32 length) noexcept; namespace NDotProduct { // Simpler wrapper allowing to use this functions as template argument. template <typename T> struct TDotProduct { using TResult = decltype(DotProduct(static_cast<const T*>(nullptr), static_cast<const T*>(nullptr), 0)); Y_PURE_FUNCTION inline TResult operator()(const T* l, const T* r, ui32 length) const { return DotProduct(l, r, length); } }; }
Kim2212/catboost
util/system/compiler.h
<reponame>Kim2212/catboost #pragma once // useful cross-platfrom definitions for compilers /** * @def Y_FUNC_SIGNATURE * * Use this macro to get pretty function name (see example). * * @code * void Hi() { * Cout << Y_FUNC_SIGNATURE << Endl; * } * template <typename T> * void Do() { * Cout << Y_FUNC_SIGNATURE << Endl; * } * int main() { * Hi(); // void Hi() * Do<int>(); // void Do() [T = int] * Do<TString>(); // void Do() [T = TString] * } * @endcode */ #if defined(__GNUC__) #define Y_FUNC_SIGNATURE __PRETTY_FUNCTION__ #elif defined(_MSC_VER) #define Y_FUNC_SIGNATURE __FUNCSIG__ #else #define Y_FUNC_SIGNATURE "" #endif #ifdef __GNUC__ #define Y_PRINTF_FORMAT(n, m) __attribute__((__format__(__printf__, n, m))) #endif #ifndef Y_PRINTF_FORMAT #define Y_PRINTF_FORMAT(n, m) #endif #if defined(__clang__) #define Y_NO_SANITIZE(...) __attribute__((no_sanitize(__VA_ARGS__))) #endif #if !defined(Y_NO_SANITIZE) #define Y_NO_SANITIZE(...) #endif /** * @def Y_DECLARE_UNUSED * * Macro is needed to silence compiler warning about unused entities (e.g. function or argument). * * @code * Y_DECLARE_UNUSED int FunctionUsedSolelyForDebugPurposes(); * assert(FunctionUsedSolelyForDebugPurposes() == 42); * * void Foo(const int argumentUsedOnlyForDebugPurposes Y_DECLARE_UNUSED) { * assert(argumentUsedOnlyForDebugPurposes == 42); * // however you may as well omit `Y_DECLARE_UNUSED` and use `UNUSED` macro instead * Y_UNUSED(argumentUsedOnlyForDebugPurposes); * } * @endcode */ #ifdef __GNUC__ #define Y_DECLARE_UNUSED __attribute__((unused)) #endif #ifndef Y_DECLARE_UNUSED #define Y_DECLARE_UNUSED #endif #if defined(__GNUC__) #define Y_LIKELY(Cond) __builtin_expect(!!(Cond), 1) #define Y_UNLIKELY(Cond) __builtin_expect(!!(Cond), 0) #define Y_PREFETCH_READ(Pointer, Priority) __builtin_prefetch((const void*)(Pointer), 0, Priority) #define Y_PREFETCH_WRITE(Pointer, Priority) __builtin_prefetch((const void*)(Pointer), 1, Priority) #endif /** * @def Y_FORCE_INLINE * * Macro to use in place of 'inline' in function declaration/definition to force * it to be inlined. */ #if !defined(Y_FORCE_INLINE) #if defined(CLANG_COVERAGE) #/* excessive __always_inline__ might significantly slow down compilation of an instrumented unit */ #define Y_FORCE_INLINE inline #elif defined(_MSC_VER) #define Y_FORCE_INLINE __forceinline #elif defined(__GNUC__) #/* Clang also defines __GNUC__ (as 4) */ #define Y_FORCE_INLINE inline __attribute__((__always_inline__)) #else #define Y_FORCE_INLINE inline #endif #endif /** * @def Y_NO_INLINE * * Macro to use in place of 'inline' in function declaration/definition to * prevent it from being inlined. */ #if !defined(Y_NO_INLINE) #if defined(_MSC_VER) #define Y_NO_INLINE __declspec(noinline) #elif defined(__GNUC__) || defined(__INTEL_COMPILER) #/* Clang also defines __GNUC__ (as 4) */ #define Y_NO_INLINE __attribute__((__noinline__)) #else #define Y_NO_INLINE #endif #endif //to cheat compiler about strict aliasing or similar problems #if defined(__GNUC__) #define Y_FAKE_READ(X) \ do { \ __asm__ __volatile__("" \ : \ : "m"(X)); \ } while (0) #define Y_FAKE_WRITE(X) \ do { \ __asm__ __volatile__("" \ : "=m"(X)); \ } while (0) #endif #if !defined(Y_FAKE_READ) #define Y_FAKE_READ(X) #endif #if !defined(Y_FAKE_WRITE) #define Y_FAKE_WRITE(X) #endif #ifndef Y_PREFETCH_READ #define Y_PREFETCH_READ(Pointer, Priority) (void)(const void*)(Pointer), (void)Priority #endif #ifndef Y_PREFETCH_WRITE #define Y_PREFETCH_WRITE(Pointer, Priority) (void)(const void*)(Pointer), (void)Priority #endif #ifndef Y_LIKELY #define Y_LIKELY(Cond) (Cond) #define Y_UNLIKELY(Cond) (Cond) #endif #ifdef __GNUC__ #define _packed __attribute__((packed)) #else #define _packed #endif #if defined(__GNUC__) #define Y_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) #endif #ifndef Y_WARN_UNUSED_RESULT #define Y_WARN_UNUSED_RESULT #endif #if defined(__GNUC__) #define Y_HIDDEN __attribute__((visibility("hidden"))) #endif #if !defined(Y_HIDDEN) #define Y_HIDDEN #endif #if defined(__GNUC__) #define Y_PUBLIC __attribute__((visibility("default"))) #endif #if !defined(Y_PUBLIC) #define Y_PUBLIC #endif #if !defined(Y_UNUSED) && !defined(__cplusplus) #define Y_UNUSED(var) (void)(var) #endif #if !defined(Y_UNUSED) && defined(__cplusplus) template <class... Types> constexpr Y_FORCE_INLINE int Y_UNUSED(Types&&...) { return 0; }; #endif /** * @def Y_ASSUME * * Macro that tells the compiler that it can generate optimized code * as if the given expression will always evaluate true. * The behavior is undefined if it ever evaluates false. * * @code * // factored into a function so that it's testable * inline int Avg(int x, int y) { * if (x >= 0 && y >= 0) { * return (static_cast<unsigned>(x) + static_cast<unsigned>(y)) >> 1; * } else { * // a slower implementation * } * } * * // we know that xs and ys are non-negative from domain knowledge, * // but we can't change the types of xs and ys because of API constrains * int Foo(const TVector<int>& xs, const TVector<int>& ys) { * TVector<int> avgs; * avgs.resize(xs.size()); * for (size_t i = 0; i < xs.size(); ++i) { * auto x = xs[i]; * auto y = ys[i]; * Y_ASSUME(x >= 0); * Y_ASSUME(y >= 0); * xs[i] = Avg(x, y); * } * } * @endcode */ #if defined(__GNUC__) #define Y_ASSUME(condition) ((condition) ? (void)0 : __builtin_unreachable()) #elif defined(_MSC_VER) #define Y_ASSUME(condition) __assume(condition) #else #define Y_ASSUME(condition) Y_UNUSED(condition) #endif #ifdef __cplusplus [[noreturn]] #endif Y_HIDDEN void _YandexAbort(); /** * @def Y_UNREACHABLE * * Macro that marks the rest of the code branch unreachable. * The behavior is undefined if it's ever reached. * * @code * switch (i % 3) { * case 0: * return foo; * case 1: * return bar; * case 2: * return baz; * default: * Y_UNREACHABLE(); * } * @endcode */ #if defined(__GNUC__) || defined(_MSC_VER) #define Y_UNREACHABLE() Y_ASSUME(0) #else #define Y_UNREACHABLE() _YandexAbort() #endif #if defined(undefined_sanitizer_enabled) #define _ubsan_enabled_ #endif #ifdef __clang__ #if __has_feature(thread_sanitizer) #define _tsan_enabled_ #endif #if __has_feature(memory_sanitizer) #define _msan_enabled_ #endif #if __has_feature(address_sanitizer) #define _asan_enabled_ #endif #else #if defined(thread_sanitizer_enabled) || defined(__SANITIZE_THREAD__) #define _tsan_enabled_ #endif #if defined(memory_sanitizer_enabled) #define _msan_enabled_ #endif #if defined(address_sanitizer_enabled) || defined(__SANITIZE_ADDRESS__) #define _asan_enabled_ #endif #endif #if defined(_asan_enabled_) || defined(_msan_enabled_) || defined(_tsan_enabled_) || defined(_ubsan_enabled_) #define _san_enabled_ #endif #if defined(_MSC_VER) #define __PRETTY_FUNCTION__ __FUNCSIG__ #endif #if defined(__GNUC__) #define Y_WEAK __attribute__((weak)) #else #define Y_WEAK #endif #if defined(__CUDACC_VER_MAJOR__) #define Y_CUDA_AT_LEAST(x, y) (__CUDACC_VER_MAJOR__ > x || (__CUDACC_VER_MAJOR__ == x && __CUDACC_VER_MINOR__ >= y)) #else #define Y_CUDA_AT_LEAST(x, y) 0 #endif // NVidia CUDA C++ Compiler did not know about noexcept keyword until version 9.0 #if !Y_CUDA_AT_LEAST(9, 0) #if defined(__CUDACC__) && !defined(noexcept) #define noexcept throw () #endif #endif #if defined(__GNUC__) #define Y_COLD __attribute__((cold)) #define Y_LEAF __attribute__((leaf)) #define Y_WRAPPER __attribute__((artificial)) #else #define Y_COLD #define Y_LEAF #define Y_WRAPPER #endif /** * @def Y_PRAGMA * * Macro for use in other macros to define compiler pragma * See below for other usage examples * * @code * #if defined(__clang__) || defined(__GNUC__) * #define Y_PRAGMA_NO_WSHADOW \ * Y_PRAGMA("GCC diagnostic ignored \"-Wshadow\"") * #elif defined(_MSC_VER) * #define Y_PRAGMA_NO_WSHADOW \ * Y_PRAGMA("warning(disable:4456 4457") * #else * #define Y_PRAGMA_NO_WSHADOW * #endif * @endcode */ #if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA(x) _Pragma(x) #elif defined(_MSC_VER) #define Y_PRAGMA(x) __pragma(x) #else #define Y_PRAGMA(x) #endif /** * @def Y_PRAGMA_DIAGNOSTIC_PUSH * * Cross-compiler pragma to save diagnostic settings * * @see * GCC: https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html * MSVC: https://msdn.microsoft.com/en-us/library/2c8f766e.aspx * Clang: https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas * * @code * Y_PRAGMA_DIAGNOSTIC_PUSH * @endcode */ #if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_DIAGNOSTIC_PUSH \ Y_PRAGMA("GCC diagnostic push") #elif defined(_MSC_VER) #define Y_PRAGMA_DIAGNOSTIC_PUSH \ Y_PRAGMA(warning(push)) #else #define Y_PRAGMA_DIAGNOSTIC_PUSH #endif /** * @def Y_PRAGMA_DIAGNOSTIC_POP * * Cross-compiler pragma to restore diagnostic settings * * @see * GCC: https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html * MSVC: https://msdn.microsoft.com/en-us/library/2c8f766e.aspx * Clang: https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas * * @code * Y_PRAGMA_DIAGNOSTIC_POP * @endcode */ #if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_DIAGNOSTIC_POP \ Y_PRAGMA("GCC diagnostic pop") #elif defined(_MSC_VER) #define Y_PRAGMA_DIAGNOSTIC_POP \ Y_PRAGMA(warning(pop)) #else #define Y_PRAGMA_DIAGNOSTIC_POP #endif /** * @def Y_PRAGMA_NO_WSHADOW * * Cross-compiler pragma to disable warnings about shadowing variables * * @code * Y_PRAGMA_DIAGNOSTIC_PUSH * Y_PRAGMA_NO_WSHADOW * * // some code which use variable shadowing, e.g.: * * for (int i = 0; i < 100; ++i) { * Use(i); * * for (int i = 42; i < 100500; ++i) { // this i is shadowing previous i * AnotherUse(i); * } * } * * Y_PRAGMA_DIAGNOSTIC_POP * @endcode */ #if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_NO_WSHADOW \ Y_PRAGMA("GCC diagnostic ignored \"-Wshadow\"") #elif defined(_MSC_VER) #define Y_PRAGMA_NO_WSHADOW \ Y_PRAGMA(warning(disable : 4456 4457)) #else #define Y_PRAGMA_NO_WSHADOW #endif /** * @ def Y_PRAGMA_NO_UNUSED_FUNCTION * * Cross-compiler pragma to disable warnings about unused functions * * @see * GCC: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html * Clang: https://clang.llvm.org/docs/DiagnosticsReference.html#wunused-function * MSVC: there is no such warning * * @code * Y_PRAGMA_DIAGNOSTIC_PUSH * Y_PRAGMA_NO_UNUSED_FUNCTION * * // some code which introduces a function which later will not be used, e.g.: * * void Foo() { * } * * int main() { * return 0; // Foo() never called * } * * Y_PRAGMA_DIAGNOSTIC_POP * @endcode */ #if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_NO_UNUSED_FUNCTION \ Y_PRAGMA("GCC diagnostic ignored \"-Wunused-function\"") #else #define Y_PRAGMA_NO_UNUSED_FUNCTION #endif /** * @ def Y_PRAGMA_NO_UNUSED_PARAMETER * * Cross-compiler pragma to disable warnings about unused function parameters * * @see * GCC: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html * Clang: https://clang.llvm.org/docs/DiagnosticsReference.html#wunused-parameter * MSVC: https://msdn.microsoft.com/en-us/library/26kb9fy0.aspx * * @code * Y_PRAGMA_DIAGNOSTIC_PUSH * Y_PRAGMA_NO_UNUSED_PARAMETER * * // some code which introduces a function with unused parameter, e.g.: * * void foo(int a) { * // a is not referenced * } * * int main() { * foo(1); * return 0; * } * * Y_PRAGMA_DIAGNOSTIC_POP * @endcode */ #if defined(__clang__) || defined(__GNUC__) #define Y_PRAGMA_NO_UNUSED_PARAMETER \ Y_PRAGMA("GCC diagnostic ignored \"-Wunused-parameter\"") #elif defined(_MSC_VER) #define Y_PRAGMA_NO_UNUSED_PARAMETER \ Y_PRAGMA(warning(disable : 4100)) #else #define Y_PRAGMA_NO_UNUSED_PARAMETER #endif #if defined(__clang__) || defined(__GNUC__) /** * @def Y_CONST_FUNCTION methods and functions, marked with this method are promised to: 1. do not have side effects 2. this method do not read global memory NOTE: this attribute can't be set for methods that depend on data, pointed by this this allow compilers to do hard optimization of that functions NOTE: in common case this attribute can't be set if method have pointer-arguments NOTE: as result there no any reason to discard result of such method */ #define Y_CONST_FUNCTION [[gnu::const]] #endif #if !defined(Y_CONST_FUNCTION) #define Y_CONST_FUNCTION #endif #if defined(__clang__) || defined(__GNUC__) /** * @def Y_PURE_FUNCTION methods and functions, marked with this method are promised to: 1. do not have side effects 2. result will be the same if no global memory changed this allow compilers to do hard optimization of that functions NOTE: as result there no any reason to discard result of such method */ #define Y_PURE_FUNCTION [[gnu::pure]] #endif #if !defined(Y_PURE_FUNCTION) #define Y_PURE_FUNCTION #endif /** * @ def Y_HAVE_INT128 * * Defined when the compiler supports __int128 extension * * @code * * #if defined(Y_HAVE_INT128) * __int128 myVeryBigInt = 12345678901234567890; * #endif * * @endcode */ #if defined(__SIZEOF_INT128__) #define Y_HAVE_INT128 1 #endif /** * XRAY macro must be passed to compiler if XRay is enabled. * * Define everything XRay-specific as a macro so that it doesn't cause errors * for compilers that doesn't support XRay. */ #if defined(XRAY) && defined(__cplusplus) #include <xray/xray_interface.h> #define Y_XRAY_ALWAYS_INSTRUMENT [[clang::xray_always_instrument]] #define Y_XRAY_NEVER_INSTRUMENT [[clang::xray_never_instrument]] #define Y_XRAY_CUSTOM_EVENT(__string, __length) \ do { \ __xray_customevent(__string, __length); \ } while (0) #else #define Y_XRAY_ALWAYS_INSTRUMENT #define Y_XRAY_NEVER_INSTRUMENT #define Y_XRAY_CUSTOM_EVENT(__string, __length) \ do { \ } while (0) #endif
Kim2212/catboost
catboost/libs/model/model_evaluator.h
<reponame>Kim2212/catboost<gh_stars>0 #pragma once #include <catboost/libs/data_util/path_with_scheme.h> #include <catboost/libs/options/load_options.h> #include <library/object_factory/object_factory.h> #include <util/generic/vector.h> namespace NCB { class IModelEvaluator { public: virtual void Apply( int argc, const char** argv, const NCB::TPathWithScheme& inputPath, const NCatboostOptions::TDsvPoolFormatParams& dsvPoolFormatParams, const TString& modelPath, EModelType modelFormat, TConstArrayRef<TString> outputColumns, ui32 iterationsLimit, const NCB::TPathWithScheme& outputPath) const = 0; virtual bool IsAcceptable(const NCB::TPathWithScheme& inputPath) const = 0; virtual bool IsReasonable(const NCB::TPathWithScheme& inputPath) const = 0; virtual ~IModelEvaluator() = default; }; using TModelEvaluatorFactory = NObjectFactory::TParametrizedObjectFactory<IModelEvaluator, TString>; }
Kim2212/catboost
util/generic/iterator.h
#pragma once #include <iterator> #include <utility> namespace NStlIterator { template <class T> struct TRefFromPtr; template <class T> struct TRefFromPtr<T*> { using TResult = T&; }; template <class T> struct TTraits { using TPtr = typename T::TPtr; using TRef = typename TRefFromPtr<TPtr>::TResult; static inline TPtr Ptr(const T& p) noexcept { return T::Ptr(p); } }; template <class T> struct TTraits<T*> { using TPtr = T*; using TRef = T&; static inline TPtr Ptr(TPtr p) noexcept { return p; } }; } template <class TSlave> class TStlIterator { public: class TIterator { public: static constexpr bool IsNoexceptNext = noexcept(std::declval<TSlave>().Next()); using TRetVal = typename TSlave::TRetVal; using TValueTraits = NStlIterator::TTraits<TRetVal>; using TPtr = typename TValueTraits::TPtr; using TRef = typename TValueTraits::TRef; using difference_type = std::ptrdiff_t; using value_type = TRetVal; using pointer = TPtr; using reference = TRef; using iterator_category = std::forward_iterator_tag; inline TIterator() noexcept : Slave_(nullptr) , Cur_() { } inline TIterator(TSlave* slave) noexcept(IsNoexceptNext) : Slave_(slave) , Cur_(Slave_->Next()) { } const TRetVal& Value() const noexcept { return Cur_; } inline bool operator==(const TIterator& it) const noexcept { return Cur_ == it.Cur_; } inline bool operator!=(const TIterator& it) const noexcept { return !(*this == it); } inline TPtr operator->() const noexcept { return TValueTraits::Ptr(Cur_); } inline TRef operator*() const noexcept { return *TValueTraits::Ptr(Cur_); } inline TIterator& operator++() noexcept(IsNoexceptNext) { Cur_ = Slave_->Next(); return *this; } private: TSlave* Slave_; TRetVal Cur_; }; public: inline TIterator begin() const noexcept(TIterator::IsNoexceptNext) { return TIterator(const_cast<TSlave*>(static_cast<const TSlave*>(this))); } inline TIterator end() const noexcept { return TIterator(); } }; /** * Transform given reverse iterator into forward iterator pointing to the same element. * * @see http://stackoverflow.com/a/1830240 */ template <class TIterator> auto ToForwardIterator(TIterator iter) { return std::next(iter).base(); }
Kim2212/catboost
catboost/libs/fstr/feature_str.h
<reponame>Kim2212/catboost<filename>catboost/libs/fstr/feature_str.h<gh_stars>0 #pragma once #include <util/generic/vector.h> #include <util/generic/ymath.h> struct TMxTree { struct TValsInLeaf { TVector<double> Vals; }; TVector<int> SrcFeatures; TVector<TValsInLeaf> Leaves; }; int GetMaxSrcFeature(const TVector<TMxTree>& trees); void ConvertToPercents(TVector<double>& res); template <class T> TVector<double> CalcEffect(const TVector<TMxTree>& trees, const TVector<TVector<T>>& weightedDocCountInLeaf) { TVector<double> res; int featureCount = GetMaxSrcFeature(trees) + 1; res.resize(featureCount); for (int treeIdx = 0; treeIdx < trees.ysize(); treeIdx++) { const auto& tree = trees[treeIdx]; for (int feature = 0; feature < tree.SrcFeatures.ysize(); feature++) { int srcIdx = tree.SrcFeatures[feature]; for (int leafIdx = 0; leafIdx < tree.Leaves.ysize(); ++leafIdx) { int inverted = leafIdx ^ (1 << feature); if (inverted < leafIdx) { continue; } double count1 = weightedDocCountInLeaf[treeIdx][leafIdx]; double count2 = weightedDocCountInLeaf[treeIdx][inverted]; if (count1 == 0 || count2 == 0) { continue; } for (int valInLeafIdx = 0; valInLeafIdx < tree.Leaves[leafIdx].Vals.ysize(); ++valInLeafIdx) { double val1 = tree.Leaves[leafIdx].Vals[valInLeafIdx]; double val2 = tree.Leaves[inverted].Vals[valInLeafIdx]; double avrg = (val1 * count1 + val2 * count2) / (count1 + count2); double dif = Sqr(val1 - avrg) * count1 + Sqr(val2 - avrg) * count2; res[srcIdx] += dif; } } } } ConvertToPercents(res); return res; } TVector<double> CalcFeaturesInfo(TVector<TVector<ui64>> trueDocsPerFeature, const ui64 docCount, bool symmetric); TVector<double> CalculateEffectToInfoRate(const TVector<double>& effect, const TVector<double>& info); struct TFeaturePairInteractionInfo { double Score; int Feature1, Feature2; TFeaturePairInteractionInfo() : Score(0) , Feature1(-1) , Feature2(-1) { } TFeaturePairInteractionInfo(double score, int f1, int f2) : Score(score) , Feature1(f1) , Feature2(f2) { } bool operator<(const TFeaturePairInteractionInfo& other) const { return Score < other.Score; } }; const int EXISTING_PAIRS_COUNT = -1; TVector<TFeaturePairInteractionInfo> CalcMostInteractingFeatures(const TVector<TMxTree>& trees, int topPairsCount = EXISTING_PAIRS_COUNT);
Kim2212/catboost
catboost/libs/metrics/dcg.h
#pragma once #include <util/generic/fwd.h> #include <util/generic/maybe.h> #include <catboost/libs/options/enums.h> // TODO(yazevnul): add fwd header for NMetrics namespace NMetrics { struct TSample; enum class ENDCGMetricType; } double CalcNdcg(TConstArrayRef<NMetrics::TSample> samples, ENdcgMetricType type = ENdcgMetricType::Base); double CalcDcg( TConstArrayRef<NMetrics::TSample> samplesRef, ENdcgMetricType type = ENdcgMetricType::Base, TMaybe<double> expDecay = Nothing()); double CalcIDcg( TConstArrayRef<NMetrics::TSample> samplesRef, ENdcgMetricType type = ENdcgMetricType::Base, TMaybe<double> expDecay = Nothing());
Kim2212/catboost
catboost/libs/data_new/feature_index.h
<gh_stars>0 #pragma once #include <catboost/libs/options/enums.h> #include <util/system/types.h> namespace NCB { template <EFeatureType FeatureType> struct TFeatureIdx { ui32 Idx; public: explicit TFeatureIdx(ui32 idx) : Idx(idx) {} // save some typing ui32 operator*() const { return Idx; } }; using TFloatFeatureIdx = TFeatureIdx<EFeatureType::Float>; using TCatFeatureIdx = TFeatureIdx<EFeatureType::Categorical>; }
Kim2212/catboost
util/generic/buffer.h
<filename>util/generic/buffer.h<gh_stars>0 #pragma once #include "utility.h" #include <util/system/align.h> #include <util/system/yassert.h> #include <cstring> class TString; class TBuffer { public: using TIterator = char*; using TConstIterator = const char*; TBuffer(size_t len = 0); TBuffer(const char* buf, size_t len); TBuffer(const TBuffer& b) : Data_(nullptr) , Len_(0) , Pos_(0) { *this = b; } TBuffer(TBuffer&& b) noexcept; TBuffer& operator=(TBuffer&& b) noexcept; TBuffer& operator=(const TBuffer& b) { if (this != &b) { Assign(b.Data(), b.Size()); } return *this; } ~TBuffer(); inline void Clear() noexcept { Pos_ = 0; } inline void EraseBack(size_t n) noexcept { Y_ASSERT(n <= Pos_); Pos_ -= n; } inline void Reset() noexcept { TBuffer().Swap(*this); } inline void Assign(const char* data, size_t len) { Clear(); Append(data, len); } inline void Assign(const char* b, const char* e) { Assign(b, e - b); } inline char* Data() noexcept { return Data_; } inline const char* Data() const noexcept { return Data_; } inline char* Pos() noexcept { return Data_ + Pos_; } inline const char* Pos() const noexcept { return Data_ + Pos_; } /// Used space in bytes (do not mix with Capacity!) inline size_t Size() const noexcept { return Pos_; } Y_PURE_FUNCTION inline bool Empty() const noexcept { return !Size(); } inline explicit operator bool() const noexcept { return Size(); } inline size_t Avail() const noexcept { return Len_ - Pos_; } void Append(const char* buf, size_t len); inline void Append(const char* b, const char* e) { Append(b, e - b); } inline void Append(char ch) { if (Len_ == Pos_) { Reserve(Len_ + 1); } *(Data() + Pos_++) = ch; } void Fill(char ch, size_t len); // Method is useful when first messages from buffer are processed, and // the last message in buffer is incomplete, so we need to move partial // message to the begin of the buffer and continue filling the buffer // from the network. inline void Chop(size_t pos, size_t count) { const auto end = pos + count; Y_ASSERT(end <= Pos_); if (count == 0) { return; } else if (count == Pos_) { Pos_ = 0; } else { memmove(Data_ + pos, Data_ + end, Pos_ - end); Pos_ -= count; } } inline void ChopHead(size_t count) { Chop(0U, count); } inline void Proceed(size_t pos) { //Y_ASSERT(pos <= Len_); // see discussion in REVIEW:29021 Resize(pos); } inline void Advance(size_t len) { Resize(Pos_ + len); } inline void Reserve(size_t len) { if (len > Len_) { DoReserve(len); } } inline void ShrinkToFit() { if (Pos_ < Len_) { Realloc(Pos_); } } inline void Resize(size_t len) { Reserve(len); Pos_ = len; } inline size_t Capacity() const noexcept { return Len_; } inline void AlignUp(size_t align, char fillChar = '\0') { size_t diff = ::AlignUp(Pos_, align) - Pos_; while (diff-- > 0) { Append(fillChar); } } /* * some helpers... */ inline char* operator~() noexcept { return Data(); } inline const char* operator~() const noexcept { return Data(); } inline size_t operator+() const noexcept { return Size(); } inline void Swap(TBuffer& r) noexcept { DoSwap(Data_, r.Data_); DoSwap(Len_, r.Len_); DoSwap(Pos_, r.Pos_); } /* * after this call buffer becomes empty */ void AsString(TString& s); /* * iterator-like interface */ inline TIterator Begin() noexcept { return Data(); } inline TIterator End() noexcept { return Begin() + Size(); } inline TConstIterator Begin() const noexcept { return Data(); } inline TConstIterator End() const noexcept { return Begin() + Size(); } private: void DoReserve(size_t len); void Realloc(size_t len); private: char* Data_; size_t Len_; size_t Pos_; };
Kim2212/catboost
library/neh/wfmo.h
#pragma once #include "lfqueue.h" #include <library/threading/atomic/bool.h> #include <util/generic/vector.h> #include <util/system/atomic.h> #include <util/system/atomic_ops.h> #include <util/system/event.h> #include <util/system/spinlock.h> namespace NNeh { template <class T> class TBlockedQueue: public TLockFreeQueue<T>, public Event { public: inline TBlockedQueue() noexcept : Event(Event::rAuto) { } inline void Notify(T t) noexcept { this->Enqueue(t); Signal(); } }; class TWaitQueue { public: struct TWaitHandle { inline TWaitHandle() noexcept : Signalled(false) , Parent(nullptr) { } inline void Signal() noexcept { TGuard<TSpinLock> lock(M_); Signalled = true; if (Parent) { Parent->Notify(this); } } inline void Register(TWaitQueue* parent) noexcept { TGuard<TSpinLock> lock(M_); Parent = parent; if (Signalled) { if (Parent) { Parent->Notify(this); } } } NAtomic::TBool Signalled; TWaitQueue* Parent; TSpinLock M_; }; inline ~TWaitQueue() { for (size_t i = 0; i < +H_; ++i) { H_[i]->Register(nullptr); } } inline void Register(TWaitHandle& ev) { H_.push_back(&ev); ev.Register(this); } template <class T> inline void Register(const T& ev) { Register(static_cast<TWaitHandle&>(*ev)); } inline bool Wait(const TInstant& deadLine) noexcept { return Q_.WaitD(deadLine); } inline void Notify(TWaitHandle* wq) noexcept { Q_.Notify(wq); } inline bool Dequeue(TWaitHandle** wq) noexcept { return Q_.Dequeue(wq); } private: TBlockedQueue<TWaitHandle*> Q_; TVector<TWaitHandle*> H_; }; typedef TWaitQueue::TWaitHandle TWaitHandle; template <class It, class T> static inline void WaitForMultipleObj(It b, It e, const TInstant& deadLine, T& func) { TWaitQueue hndl; while (b != e) { hndl.Register(*b++); } do { TWaitHandle* ret = nullptr; if (hndl.Dequeue(&ret)) { do { func(ret); } while (hndl.Dequeue(&ret)); return; } } while (hndl.Wait(deadLine)); } struct TSignalled { inline TSignalled() : Signalled(false) { } inline void operator()(const TWaitHandle*) noexcept { Signalled = true; } bool Signalled; }; static inline bool WaitForOne(TWaitHandle& wh, const TInstant& deadLine) { TSignalled func; WaitForMultipleObj(&wh, &wh + 1, deadLine, func); return func.Signalled; } }
Kim2212/catboost
catboost/libs/data_new/ut/lib/for_data_provider.h
#pragma once #include <catboost/libs/data_new/data_provider.h> #include <catboost/libs/data_new/meta_info.h> #include <catboost/libs/data_new/objects_grouping.h> #include <catboost/libs/data_new/objects.h> #include <catboost/libs/data_new/quantized_features_info.h> #include <catboost/libs/data_new/target.h> #include <catboost/libs/data_types/groupid.h> #include <library/unittest/registar.h> #include <util/generic/maybe.h> #include <util/generic/ptr.h> #include <util/generic/strbuf.h> #include <util/generic/vector.h> #include <util/system/types.h> namespace NCB { namespace NDataNewUT { template <class TGroupIdData, class TSubgroupIdData, class TFloatFeature, class TCatFeature> struct TExpectedCommonObjectsData { EObjectsOrder Order = EObjectsOrder::Undefined; // Objects data TMaybe<TVector<TGroupIdData>> GroupIds; TMaybe<TVector<TSubgroupIdData>> SubgroupIds; TMaybe<TVector<ui64>> Timestamp; TVector<TMaybe<TVector<TFloatFeature>>> FloatFeatures; TVector<TMaybe<TVector<TCatFeature>>> CatFeatures; }; /* * GroupIds will be processed with CalcGroupIdFor * SubgroupIds will be processed with CalcSubgroupIdFor * CatFeatures will be processed with CalcCatFeatureHash */ struct TExpectedRawObjectsData : public TExpectedCommonObjectsData<TStringBuf, TStringBuf, float, TStringBuf> {}; // TODO(akhropov): quantized pools might have more complicated features data types in the future struct TExpectedQuantizedObjectsData : public TExpectedCommonObjectsData<TGroupId, TSubgroupId, ui8, ui32> { TQuantizedFeaturesInfoPtr QuantizedFeaturesInfo; // only for TQuantizedForCPUDataProvider TMaybe<TVector<TCatFeatureUniqueValuesCounts>> CatFeatureUniqueValuesCounts; }; template <class TExpectedObjectsData> struct TExpectedData { TDataMetaInfo MetaInfo; TExpectedObjectsData Objects; TObjectsGrouping ObjectsGrouping = TObjectsGrouping(0); TRawTargetData Target; }; using TExpectedRawData = TExpectedData<TExpectedRawObjectsData>; using TExpectedQuantizedData = TExpectedData<TExpectedQuantizedObjectsData>; void CompareObjectsData(const TRawObjectsDataProvider& objectsData, const TExpectedRawData& expectedData); void CompareObjectsData( const TQuantizedObjectsDataProvider& objectsData, const TExpectedQuantizedData& expectedData ); void CompareObjectsData( const TQuantizedForCPUObjectsDataProvider& objectsData, const TExpectedQuantizedData& expectedData ); void CompareTargetData( const TRawTargetDataProvider& targetData, const TObjectsGrouping& expectedObjectsGrouping, const TRawTargetData& expectedData ); template <class TObjectsDataProvider, class TExpectedObjectsDataProvider> void Compare( TDataProviderPtr dataProvider, const TExpectedData<TExpectedObjectsDataProvider>& expectedData ) { const TIntrusivePtr<TDataProviderTemplate<TObjectsDataProvider>> subtypeDataProvider = dataProvider->CastMoveTo<TObjectsDataProvider>(); UNIT_ASSERT(subtypeDataProvider); UNIT_ASSERT_EQUAL(subtypeDataProvider->MetaInfo, expectedData.MetaInfo); CompareObjectsData(*(subtypeDataProvider->ObjectsData), expectedData); UNIT_ASSERT_EQUAL(*subtypeDataProvider->ObjectsGrouping, expectedData.ObjectsGrouping); CompareTargetData( subtypeDataProvider->RawTargetData, expectedData.ObjectsGrouping, expectedData.Target ); } } }
Kim2212/catboost
catboost/cuda/cpu_compatibility_helpers/cpu_pool_based_data_provider_builder.h
<filename>catboost/cuda/cpu_compatibility_helpers/cpu_pool_based_data_provider_builder.h #pragma once #include "externel_cat_values_holder.h" #include <catboost/libs/data/pool.h> #include <catboost/libs/logging/logging.h> #include <catboost/cuda/data/data_provider.h> #include <catboost/cuda/data/binarizations_manager.h> #include <catboost/cuda/data/cat_feature_perfect_hash_helper.h> #include <catboost/libs/helpers/cpu_random.h> namespace NCatboostCuda { class TCpuPoolBasedDataProviderBuilder { public: TCpuPoolBasedDataProviderBuilder(TBinarizedFeaturesManager& featureManager, bool hasQueries, const TPool& pool, bool isTest, const NCatboostOptions::TLossDescription& lossFunctionDescription, ui64 seed, TDataProvider& dst); template <class TContainer> TCpuPoolBasedDataProviderBuilder& AddIgnoredFeatures(const TContainer& container) { for (const auto& f : container) { IgnoreFeatures.insert(f); } return *this; } TCpuPoolBasedDataProviderBuilder& SetTargetHelper(TSimpleSharedPtr<TClassificationTargetHelper> targetHelper) { TargetHelper = targetHelper; return *this; } void Finish(ui32 binarizationThreads); private: void RegisterFeaturesInFeatureManager(const TSet<int>& catFeatureIds) const { const ui32 factorsCount = Pool.Docs.GetEffectiveFactorCount(); for (ui32 featureId = 0; featureId < factorsCount; ++featureId) { if (!FeaturesManager.IsKnown(featureId)) { if (catFeatureIds.has(featureId)) { FeaturesManager.RegisterDataProviderCatFeature(featureId); } else { FeaturesManager.RegisterDataProviderFloatFeature(featureId); } } } } private: TBinarizedFeaturesManager& FeaturesManager; TDataProvider& DataProvider; const TPool& Pool; bool IsTest; TCatFeaturesPerfectHashHelper CatFeaturesPerfectHashHelper; TSet<ui32> IgnoreFeatures; TSimpleSharedPtr<TClassificationTargetHelper> TargetHelper; }; }
Kim2212/catboost
library/threading/name_guard/name_guard.h
<filename>library/threading/name_guard/name_guard.h<gh_stars>0 #pragma once #include <util/generic/strbuf.h> #include <util/generic/string.h> #include <util/system/compiler.h> // RAII primitive to set/unset thread name within scope namespace NThreading { class TThreadNameGuard { public: ~TThreadNameGuard(); static TThreadNameGuard Make(TStringBuf name); private: TThreadNameGuard(TStringBuf name); TThreadNameGuard(TThreadNameGuard&&); TThreadNameGuard(const TThreadNameGuard&) = delete; TThreadNameGuard& operator =(const TThreadNameGuard&) = delete; TThreadNameGuard& operator =(TThreadNameGuard&&) = delete; private: TString PreviousThreadName_; }; } #define Y_THREAD_NAME_GUARD(name) \ const auto Y_GENERATE_UNIQUE_ID(threadNameGuard) = ::NThreading::TThreadNameGuard::Make(name);
Kim2212/catboost
util/generic/set.h
#pragma once #include "fwd.h" #include <util/str_stl.h> #include <util/memory/alloc.h> #include <initializer_list> #include <memory> #include <set> template <class K, class L, class A> class TSet: public std::set<K, L, TReboundAllocator<A, K>> { using TBase = std::set<K, L, TReboundAllocator<A, K>>; using TSelf = TSet<K, L, A>; using TKeyCompare = typename TBase::key_compare; using TAllocatorType = typename TBase::allocator_type; public: inline TSet() { } template <class It> inline TSet(It f, It l) : TBase(f, l) { } inline TSet(std::initializer_list<K> il, const TKeyCompare& comp = TKeyCompare(), const TAllocatorType& alloc = TAllocatorType()) : TBase(il, comp, alloc) { } inline TSet(const TSelf& src) : TBase(src) { } inline TSet(TSelf&& src) noexcept : TBase(std::forward<TSelf>(src)) { } inline TSelf& operator=(const TSelf& src) { TBase::operator=(src); return *this; } inline TSelf& operator=(TSelf&& src) noexcept { TBase::operator=(std::forward<TSelf>(src)); return *this; } Y_PURE_FUNCTION inline bool empty() const noexcept { return TBase::empty(); } inline explicit operator bool() const noexcept { return !this->empty(); } template <class TheKey> inline bool has(const TheKey& key) const { return this->find(key) != this->end(); } }; template <class K, class L, class A> class TMultiSet: public std::multiset<K, L, TReboundAllocator<A, K>> { using TBase = std::multiset<K, L, TReboundAllocator<A, K>>; using TSelf = TMultiSet<K, L, A>; using TKeyCompare = typename TBase::key_compare; using TAllocatorType = typename TBase::allocator_type; public: inline TMultiSet() { } template <class It> inline TMultiSet(It f, It l) : TBase(f, l) { } inline TMultiSet(std::initializer_list<K> il, const TKeyCompare& comp = TKeyCompare(), const TAllocatorType& alloc = TAllocatorType()) : TBase(il, comp, alloc) { } inline TMultiSet(const TSelf& src) : TBase(src) { } inline TMultiSet(TSelf&& src) noexcept { this->swap(src); } inline TSelf& operator=(const TSelf& src) { TBase::operator=(src); return *this; } inline TSelf& operator=(TSelf&& src) noexcept { // Self-move assignment is undefined behavior in the Standard. // This implementation ends up with zero-sized multiset. this->clear(); this->swap(src); return *this; } Y_PURE_FUNCTION inline bool empty() const noexcept { return TBase::empty(); } inline explicit operator bool() const noexcept { return !this->empty(); } };
Kim2212/catboost
catboost/libs/options/option.h
<reponame>Kim2212/catboost #pragma once #include <catboost/libs/helpers/exception.h> #include <util/generic/string.h> #include <tuple> #include <utility> namespace NCatboostOptions { template <class TValue> class TOption { public: TOption(TString key, const TValue& defaultValue) : Value(defaultValue) , DefaultValue(defaultValue) , OptionName(std::move(key)) { } TOption(const TOption& other) = default; virtual ~TOption() { } template <class T> void SetDefault(T&& value) { DefaultValue = std::forward<T>(value); if (!IsSetFlag) { Value = DefaultValue; } } template <class T> void Set(T&& value) { Value = std::forward<T>(value); IsSetFlag = true; } virtual const TValue& Get() const { return Value; } virtual TValue& Get() { CB_ENSURE(!IsDisabled(), "Error: option " << OptionName << " is disabled"); return Value; } inline TValue* operator->() noexcept { return &Value; } //disabled options would not be serialized/deserialized bool IsDisabled() const { return IsDisabledFlag; } bool IsDefault() const { return Value == DefaultValue; } void SetDisabledFlag(bool flag) { IsDisabledFlag = flag; } inline const TValue* operator->() const noexcept { return &Value; } bool IsSet() const { return IsSetFlag; } bool NotSet() const { return !IsSet(); } const TString& GetName() const { return OptionName; } operator const TValue&() const { return Get(); } operator TValue&() { return Get(); } bool operator==(const TOption& rhs) const { return std::tie(Value, OptionName) == std::tie(rhs.Value, rhs.OptionName); } bool operator!=(const TOption& rhs) const { return !(rhs == *this); } template <typename TComparableType> bool operator==(const TComparableType& otherValue) const { return Value == otherValue; } template <typename TComparableType> bool operator!=(const TComparableType& otherValue) const { return Value != otherValue; } inline TOption& operator=(const TValue& value) { Set(value); return *this; } inline TOption& operator=(const TOption& other) = default; private: template <class> friend struct ::THash; template <class, bool> friend class TJsonFieldHelper; private: TValue Value; TValue DefaultValue; TString OptionName; bool IsSetFlag = false; bool IsDisabledFlag = false; }; } template <class T> struct THash<NCatboostOptions::TOption<T>> { size_t operator()(const NCatboostOptions::TOption<T>& option) const noexcept { return THash<T>()(option.Value); } }; template <class T> inline IOutputStream& operator<<(IOutputStream& o, const NCatboostOptions::TOption<T>& option) { o << option.Get(); return o; }
Kim2212/catboost
catboost/libs/helpers/vector_helpers.h
<reponame>Kim2212/catboost<filename>catboost/libs/helpers/vector_helpers.h #pragma once #include <util/generic/array_ref.h> #include <util/generic/vector.h> #include <util/generic/algorithm.h> #include <util/generic/ymath.h> #include <algorithm> template <typename T> static TVector<const T*> GetConstPointers(const TVector<T>& objects) { TVector<const T*> result(objects.size()); for (size_t i = 0; i < objects.size(); ++i) { result[i] = &objects[i]; } return result; } template <typename T> static TVector<T*> GetMutablePointers(TVector<T>& objects) { TVector<T*> result(objects.size()); for (size_t i = 0; i < objects.size(); ++i) { result[i] = &objects[i]; } return result; } template <typename T> static TVector<const T*> GetConstPointers(const TVector<THolder<T>>& holders) { TVector<const T*> result(holders.size()); for (size_t i = 0; i < holders.size(); ++i) { result[i] = holders[i].Get(); } return result; } template <typename T> struct TMinMax { T Min; T Max; }; template <typename TForwardIterator, typename T = typename std::iterator_traits<TForwardIterator>::value_type> inline TMinMax<T> CalcMinMax(TForwardIterator begin, TForwardIterator end) { auto minmax = std::minmax_element(begin, end); Y_VERIFY(minmax.first != end); return {*minmax.first, *minmax.second}; } template <typename T> inline TMinMax<T> CalcMinMax(const TVector<T>& v) { return CalcMinMax(v.begin(), v.end()); } inline bool IsConst(const TVector<float>& values) { if (values.empty()) { return true; } auto bounds = CalcMinMax(values); return bounds.Min == bounds.Max; } template <typename Int1, typename Int2, typename T> inline void ResizeRank2(Int1 dim1, Int2 dim2, TVector<TVector<T>>& vvt) { vvt.resize(dim1); for (auto& vt : vvt) { vt.resize(dim2); } } template <class T> void Assign(TConstArrayRef<T> arrayRef, TVector<T>* v) { v->assign(arrayRef.begin(), arrayRef.end()); } template <class T> bool Equal(TConstArrayRef<T> arrayRef, const TVector<T>& v) { return arrayRef == TConstArrayRef<T>(v); } template <class T> bool ApproximatelyEqual(TConstArrayRef<T> lhs, TConstArrayRef<T> rhs, const T eps) { return std::equal( lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), [eps](T lElement, T rElement) { return Abs(lElement - rElement) < eps; } ); }
Kim2212/catboost
catboost/libs/data_new/ut/lib/for_loader.h
#pragma once #include <catboost/libs/data_util/path_with_scheme.h> #include <util/generic/ptr.h> #include <util/generic/strbuf.h> #include <util/generic/vector.h> #include <util/system/tempfile.h> namespace NCB { namespace NDataNewUT { void SaveDataToTempFile( TStringBuf srcData, TPathWithScheme* dstPath, // TODO(akhropov): temporarily use THolder until TTempFile move semantic is fixed TVector<THolder<TTempFile>>* srcDataFiles ); } }
Kim2212/catboost
contrib/deprecated/libffi/include/ffitarget.h
<reponame>Kim2212/catboost #pragma once #if defined(__IOS__) #ifdef __arm64__ #include <ios/ffitarget_arm64.h> #endif #ifdef __i386__ #include <ios/ffitarget_i386.h> #endif #ifdef __arm__ #include <ios/ffitarget_armv7.h> #endif #ifdef __x86_64__ #include <ios/ffitarget_x86_64.h> #endif #else #if defined(__linux__) #define X86_64 #endif #if defined(__APPLE__) #define X86_DARWIN #endif #if defined(_MSC_VER) #define X86_WIN64 #endif #include "../src/x86/ffitarget.h" #endif
Kim2212/catboost
catboost/libs/model/ut/model_test_helpers.h
#pragma once #include <catboost/libs/data/pool.h> #include <catboost/libs/model/model.h> TFullModel TrainFloatCatboostModel(); TPool GetAdultPool();
Kim2212/catboost
catboost/libs/algo/train_templ.h
<reponame>Kim2212/catboost<filename>catboost/libs/algo/train_templ.h #pragma once #include "approx_calcer.h" #include "fold.h" #include "greedy_tensor_search.h" #include "online_ctr.h" #include "tensor_search_helpers.h" #include <catboost/libs/distributed/worker.h> #include <catboost/libs/distributed/master.h> #include <catboost/libs/helpers/interrupt.h> #include <catboost/libs/logging/profile_info.h> struct TCompetitor; template <typename TError> void UpdateLearningFold( const TDataset& learnData, const TDatasetPtrs& testDataPtrs, const TError& error, const TSplitTree& bestSplitTree, ui64 randomSeed, TFold* fold, TLearnContext* ctx ) { TVector<TVector<TVector<double>>> approxDelta; CalcApproxForLeafStruct( learnData, testDataPtrs, error, *fold, bestSplitTree, randomSeed, ctx, &approxDelta ); UpdateBodyTailApprox<TError::StoreExpApprox>(approxDelta, ctx->Params.BoostingOptions->LearningRate, &ctx->LocalExecutor, fold); } template <typename TError> void UpdateAveragingFold( const TDataset& learnData, const TDatasetPtrs& testDataPtrs, const TError& error, const TSplitTree& bestSplitTree, TLearnContext* ctx, TVector<TVector<double>>* treeValues ) { TProfileInfo& profile = ctx->Profile; TVector<TIndexType> indices; CalcLeafValues( learnData, testDataPtrs, error, ctx->LearnProgress.AveragingFold, bestSplitTree, ctx, treeValues, &indices ); const size_t leafCount = (*treeValues)[0].size(); ctx->LearnProgress.TreeStats.emplace_back(); ctx->LearnProgress.TreeStats.back().LeafWeightsSum = SumLeafWeights(leafCount, indices, ctx->LearnProgress.AveragingFold.LearnPermutation, learnData.Weights); if (IsPairwiseError(ctx->Params.LossFunctionDescription->GetLossFunction())) { const auto& leafWeightsSum = ctx->LearnProgress.TreeStats.back().LeafWeightsSum; double averageLeafValue = 0; for (size_t leafIdx : xrange(leafWeightsSum.size())) { averageLeafValue += (*treeValues)[0][leafIdx] * leafWeightsSum[leafIdx]; } averageLeafValue /= Accumulate(leafWeightsSum, /*val*/0.0); for (auto& leafValue : (*treeValues)[0]) { leafValue -= averageLeafValue; } } const int approxDimension = ctx->LearnProgress.AvrgApprox.ysize(); const double learningRate = ctx->Params.BoostingOptions->LearningRate; TVector<TVector<double>> expTreeValues; expTreeValues.yresize(approxDimension); for (int dim = 0; dim < approxDimension; ++dim) { for (auto& leafVal : (*treeValues)[dim]) { leafVal *= learningRate; } expTreeValues[dim] = (*treeValues)[dim]; ExpApproxIf(TError::StoreExpApprox, &expTreeValues[dim]); } profile.AddOperation("CalcApprox result leaves"); CheckInterrupted(); // check after long-lasting operation Y_ASSERT(ctx->LearnProgress.AveragingFold.BodyTailArr.ysize() == 1); const size_t learnSampleCount = learnData.GetSampleCount(); const TVector<size_t>& testOffsets = CalcTestOffsets(learnSampleCount, testDataPtrs); ctx->LocalExecutor.ExecRange([&](int setIdx){ if (setIdx == 0) { // learn data set TConstArrayRef<TIndexType> indicesRef(indices); const auto updateApprox = [=](TConstArrayRef<double> delta, TArrayRef<double> approx, size_t idx) { approx[idx] = UpdateApprox<TError::StoreExpApprox>(approx[idx], delta[indicesRef[idx]]); }; TFold::TBodyTail& bt = ctx->LearnProgress.AveragingFold.BodyTailArr[0]; Y_ASSERT(bt.Approx[0].ysize() == bt.TailFinish); UpdateApprox(updateApprox, expTreeValues, &bt.Approx, &ctx->LocalExecutor); TConstArrayRef<ui32> learnPermutationRef(ctx->LearnProgress.AveragingFold.LearnPermutation); const auto updateAvrgApprox = [=](TConstArrayRef<double> delta, TArrayRef<double> approx, size_t idx) { approx[learnPermutationRef[idx]] += delta[indicesRef[idx]]; }; Y_ASSERT(ctx->LearnProgress.AvrgApprox[0].size() == learnSampleCount); UpdateApprox(updateAvrgApprox, *treeValues, &ctx->LearnProgress.AvrgApprox, &ctx->LocalExecutor); } else { // test data set const int testIdx = setIdx - 1; const size_t testSampleCount = testDataPtrs[testIdx]->GetSampleCount(); TConstArrayRef<TIndexType> indicesRef(indices.data() + testOffsets[testIdx], testSampleCount); const auto updateTestApprox = [=](TConstArrayRef<double> delta, TArrayRef<double> approx, size_t idx) { approx[idx] += delta[indicesRef[idx]]; }; Y_ASSERT(ctx->LearnProgress.TestApprox[testIdx][0].size() == testSampleCount); UpdateApprox(updateTestApprox, *treeValues, &ctx->LearnProgress.TestApprox[testIdx], &ctx->LocalExecutor); } }, 0, 1 + testDataPtrs.ysize(), NPar::TLocalExecutor::WAIT_COMPLETE); } template <typename TError> void TrainOneIter(const TDataset& learnData, const TDatasetPtrs& testDataPtrs, TLearnContext* ctx) { ctx->LearnProgress.HessianType = TError::GetHessianType(); TError error = BuildError<TError>(ctx->Params, ctx->ObjectiveDescriptor); CheckDerivativeOrderForTrain( error.GetMaxSupportedDerivativeOrder(), ctx->Params.ObliviousTreeOptions->LeavesEstimationMethod ); TProfileInfo& profile = ctx->Profile; const TVector<int> splitCounts = CountSplits(ctx->LearnProgress.FloatFeatures); const int foldCount = ctx->LearnProgress.Folds.ysize(); const int currentIteration = ctx->LearnProgress.TreeStruct.ysize(); const double modelLength = currentIteration * ctx->Params.BoostingOptions->LearningRate; CheckInterrupted(); // check after long-lasting operation TSplitTree bestSplitTree; { TFold* takenFold = &ctx->LearnProgress.Folds[ctx->Rand.GenRand() % foldCount]; const TVector<ui64> randomSeeds = GenRandUI64Vector(takenFold->BodyTailArr.ysize(), ctx->Rand.GenRand()); if (ctx->Params.SystemOptions->IsSingleHost()) { ctx->LocalExecutor.ExecRange([&](int bodyTailId) { CalcWeightedDerivatives(error, bodyTailId, ctx->Params, randomSeeds[bodyTailId], takenFold, &ctx->LocalExecutor); }, 0, takenFold->BodyTailArr.ysize(), NPar::TLocalExecutor::WAIT_COMPLETE); } else { Y_ASSERT(takenFold->BodyTailArr.ysize() == 1); MapSetDerivatives<TError>(ctx); } profile.AddOperation("Calc derivatives"); GreedyTensorSearch( learnData, testDataPtrs, splitCounts, modelLength, profile, takenFold, ctx, &bestSplitTree ); } CheckInterrupted(); // check after long-lasting operation { TVector<TFold*> trainFolds; for (int foldId = 0; foldId < foldCount; ++foldId) { trainFolds.push_back(&ctx->LearnProgress.Folds[foldId]); } TrimOnlineCTRcache(trainFolds); TrimOnlineCTRcache({ &ctx->LearnProgress.AveragingFold }); { TVector<TFold*> allFolds = trainFolds; allFolds.push_back(&ctx->LearnProgress.AveragingFold); struct TLocalJobData { const TDataset* LearnData; const TDatasetPtrs& TestDatas; TProjection Projection; TFold* Fold; TOnlineCTR* Ctr; void DoTask(TLearnContext* ctx) { ComputeOnlineCTRs(*LearnData, TestDatas, *Fold, Projection, ctx, Ctr); } }; TVector<TLocalJobData> parallelJobsData; THashSet<TProjection> seenProjections; for (const auto& split : bestSplitTree.Splits) { if (split.Type != ESplitType::OnlineCtr) { continue; } const auto& proj = split.Ctr.Projection; if (seenProjections.has(proj)) { continue; } for (auto* foldPtr : allFolds) { if (!foldPtr->GetCtrs(proj).has(proj) || foldPtr->GetCtr(proj).Feature.empty()) { parallelJobsData.emplace_back(TLocalJobData{ &learnData, testDataPtrs, proj, foldPtr, &foldPtr->GetCtrRef(proj) }); } } seenProjections.insert(proj); } ctx->LocalExecutor.ExecRange([&](int taskId){ parallelJobsData[taskId].DoTask(ctx); }, 0, parallelJobsData.size(), NPar::TLocalExecutor::WAIT_COMPLETE); } profile.AddOperation("ComputeOnlineCTRs for tree struct (train folds and test fold)"); CheckInterrupted(); // check after long-lasting operation if (ctx->Params.SystemOptions->IsSingleHost()) { const TVector<ui64> randomSeeds = GenRandUI64Vector(foldCount, ctx->Rand.GenRand()); ctx->LocalExecutor.ExecRange([&](int foldId) { UpdateLearningFold(learnData, testDataPtrs, error, bestSplitTree, randomSeeds[foldId], trainFolds[foldId], ctx); }, 0, foldCount, NPar::TLocalExecutor::WAIT_COMPLETE); } else { if (ctx->LearnProgress.AveragingFold.GetApproxDimension() == 1) { MapSetApproxesSimple<TError>(bestSplitTree, ctx); } else { MapSetApproxesMulti<TError>(bestSplitTree, ctx); } } profile.AddOperation("CalcApprox tree struct and update tree structure approx"); CheckInterrupted(); // check after long-lasting operation TVector<TVector<double>> treeValues; // [dim][leafId] UpdateAveragingFold(learnData, testDataPtrs, error, bestSplitTree, ctx, &treeValues); ctx->LearnProgress.LeafValues.push_back(treeValues); ctx->LearnProgress.TreeStruct.push_back(bestSplitTree); profile.AddOperation("Update final approxes"); CheckInterrupted(); // check after long-lasting operation } }
Kim2212/catboost
contrib/libs/python/Include/bytesobject.h
#pragma once #ifdef USE_PYTHON3 #include <contrib/tools/python3/src/Include/bytesobject.h> #else #include <contrib/tools/python/src/Include/bytesobject.h> #endif
Kim2212/catboost
catboost/libs/algo/pairwise_scoring.h
<gh_stars>0 #pragma once #include "calc_score_cache.h" #include "index_calcer.h" #include "score_bin.h" #include "split.h" #include <catboost/libs/index_range/index_range.h> #include <library/binsaver/bin_saver.h> struct TBucketPairWeightStatistics { double SmallerBorderWeightSum = 0.0; // The weight sum of pair elements with smaller border. double GreaterBorderRightWeightSum = 0.0; // The weight sum of pair elements with greater border. void Add(const TBucketPairWeightStatistics& rhs) { SmallerBorderWeightSum += rhs.SmallerBorderWeightSum; GreaterBorderRightWeightSum += rhs.GreaterBorderRightWeightSum; } SAVELOAD(SmallerBorderWeightSum, GreaterBorderRightWeightSum); }; struct TPairwiseStats { TVector<TVector<double>> DerSums; // [leafCount][bucketCount] TArray2D<TVector<TBucketPairWeightStatistics>> PairWeightStatistics; // [leafCount][leafCount][bucketCount] void Add(const TPairwiseStats& rhs); SAVELOAD(DerSums, PairWeightStatistics); }; template <typename TBucketIndexType> TVector<TVector<double>> ComputeDerSums( TConstArrayRef<double> weightedDerivativesData, int leafCount, int bucketCount, const TVector<TIndexType>& leafIndices, const TVector<TBucketIndexType>& bucketIndices, NCB::TIndexRange<int> docIndexRange ); template <typename TBucketIndexType> TArray2D<TVector<TBucketPairWeightStatistics>> ComputePairWeightStatistics( const TFlatPairsInfo& pairs, int leafCount, int bucketCount, const TVector<TIndexType>& leafIndices, const TVector<TBucketIndexType>& bucketIndices, NCB::TIndexRange<int> pairIndexRange ); void CalculatePairwiseScore( const TPairwiseStats& pairwiseStats, int bucketCount, ESplitType splitType, float l2DiagReg, float pairwiseBucketWeightPriorReg, TVector<TScoreBin>* scoreBins );
Kim2212/catboost
catboost/cuda/data/load_data.h
<gh_stars>0 #pragma once #include "data_provider.h" #include "binarizations_manager.h" #include "cat_feature_perfect_hash_helper.h" #include "binarized_features_meta_info.h" #include "classification_target_helper.h" #include <catboost/cuda/utils/helpers.h> #include <catboost/libs/data/load_data.h> #include <catboost/libs/data_types/pair.h> #include <catboost/libs/helpers/cpu_random.h> #include <catboost/libs/helpers/exception.h> #include <catboost/libs/logging/logging.h> #include <catboost/libs/options/loss_description.h> #include <catboost/libs/pairs/util.h> #include <catboost/libs/quantization/utils.h> #include <library/threading/local_executor/fwd.h> #include <util/random/shuffle.h> #include <util/stream/file.h> #include <util/system/atomic.h> #include <util/system/atomic_ops.h> #include <util/system/sem.h> #include <util/system/spinlock.h> namespace NCB { struct TPathWithScheme; } namespace NCatboostCuda { class TDataProviderBuilder: public NCB::IPoolBuilder { public: TDataProviderBuilder(TBinarizedFeaturesManager& featureManager, TDataProvider& dst, bool isTest = false, const int buildThreads = 1) : FeaturesManager(featureManager) , DataProvider(dst) , IsTest(isTest) , BuildThreads(buildThreads) , CatFeaturesPerfectHashHelper(FeaturesManager) { } template <class TContainer> TDataProviderBuilder& AddIgnoredFeatures(const TContainer& container) { for (const auto& f : container) { IgnoreFeatures.insert(f); } return *this; } TDataProviderBuilder& SetTargetHelper(TSimpleSharedPtr<TClassificationTargetHelper> helper) { TargetHelper = helper; return *this; } TDataProviderBuilder& SetBinarizedFeaturesMetaInfo(const TBinarizedFloatFeaturesMetaInfo& binarizedFeaturesMetaInfo) { BinarizedFeaturesMetaInfo = binarizedFeaturesMetaInfo; return *this; } void Start(const TPoolMetaInfo& poolMetaInfo, int docCount, const TVector<int>& catFeatureIds) override; TDataProviderBuilder& SetShuffleFlag(bool shuffle, ui64 seed = 0) { ShuffleFlag = shuffle; Seed = seed; return *this; } void StartNextBlock(ui32 blockSize) override; float GetCatFeatureValue(const TStringBuf& feature) override { return ConvertCatFeatureHashToFloat(StringToIntHash(feature)); } void AddCatFeature(ui32 localIdx, ui32 featureId, const TStringBuf& feature) override { if (IgnoreFeatures.count(featureId) == 0) { Y_ASSERT(FeatureTypes[featureId] == EFeatureValuesType::Categorical); WriteFloatOrCatFeatureToBlobImpl(localIdx, featureId, ConvertCatFeatureHashToFloat(StringToIntHash(feature))); } } void AddFloatFeature(ui32 localIdx, ui32 featureId, float feature) override { if (IgnoreFeatures.count(featureId) == 0) { switch (FeatureTypes[featureId]) { case EFeatureValuesType::BinarizedFloat: { ui8 binarizedFeature = NCB::Binarize<ui8>( NanModes[featureId], Borders[featureId], feature ); WriteBinarizedFeatureToBlobImpl(localIdx, featureId, binarizedFeature); break; } case EFeatureValuesType::Float: { WriteFloatOrCatFeatureToBlobImpl(localIdx, featureId, feature); break; } default: { CB_ENSURE(false, "Unsupported type " << FeatureTypes[featureId]); } } } } void AddBinarizedFloatFeature(ui32 localIdx, ui32 featureId, ui8 binarizedFeature) override { if (IgnoreFeatures.count(featureId) == 0) { CB_ENSURE(FeatureTypes[featureId] == EFeatureValuesType::BinarizedFloat, "FeatureValueType doesn't match: expect BinarizedFloat, got " << FeatureTypes[featureId]); WriteBinarizedFeatureToBlobImpl(localIdx, featureId, binarizedFeature); } } void AddBinarizedFloatFeaturePack(ui32 localIdx, ui32 featureId, TConstArrayRef<ui8> binarizedFeaturePack) override { if (IgnoreFeatures.count(featureId) == 0) { CB_ENSURE(FeatureTypes[featureId] == EFeatureValuesType::BinarizedFloat, "FeatureValueType doesn't match: expect BinarizedFloat, got " << FeatureTypes[featureId]); for (ui8 binarizedFeature : binarizedFeaturePack) { WriteBinarizedFeatureToBlobImpl(localIdx, featureId, binarizedFeature); ++localIdx; } } } void AddAllFloatFeatures(ui32 localIdx, TConstArrayRef<float> features) override { CB_ENSURE(features.size() == FeatureBlobs.size(), "Error: number of features should be equal to factor count"); for (size_t featureId = 0; featureId < FeatureBlobs.size(); ++featureId) { if (IgnoreFeatures.count(featureId) == 0) { if (FeatureTypes[featureId] == EFeatureValuesType::Categorical) { WriteFloatOrCatFeatureToBlobImpl(localIdx, featureId, features[featureId]); } else { AddFloatFeature(localIdx, featureId, features[featureId]); } } } } void AddLabel(ui32 localIdx, const TStringBuf& value) final { Labels[GetLineIdx(localIdx)] = value; } void AddTarget(ui32 localIdx, float value) override { if (Y_UNLIKELY(!IsSafeTarget(value))) { WriteUnsafeTargetWarningOnce(localIdx, value); } DataProvider.Targets[GetLineIdx(localIdx)] = value; } void AddWeight(ui32 localIdx, float value) override { DataProvider.Weights[GetLineIdx(localIdx)] = value; } void AddQueryId(ui32 localIdx, TGroupId queryId) override { DataProvider.QueryIds[GetLineIdx(localIdx)] = queryId; } void AddSubgroupId(ui32 localIdx, TSubgroupId groupId) override { DataProvider.SubgroupIds[GetLineIdx(localIdx)] = groupId; } void AddBaseline(ui32 localIdx, ui32 baselineIdx, double value) override { DataProvider.Baseline[baselineIdx][GetLineIdx(localIdx)] = (float)value; } void AddTimestamp(ui32 localIdx, ui64 timestamp) override { DataProvider.Timestamp[GetLineIdx(localIdx)] = timestamp; } void SetFeatureIds(const TVector<TString>& featureIds) override { FeatureNames = featureIds; } void SetPairs(const TVector<TPair>& pairs) override { CB_ENSURE(!IsDone, "Error: can't set pairs after finish"); Pairs = pairs; } void SetGroupWeights(const TVector<float>& groupWeights) override { CB_ENSURE(!IsDone, "Error: can't set group weights after finish"); CB_ENSURE(DataProvider.GetSampleCount() == groupWeights.size(), "Group weights file should have as many weights as the objects in the dataset."); DataProvider.Weights = groupWeights; } void GeneratePairs(const NCatboostOptions::TLossDescription& lossFunctionDescription) { CB_ENSURE(Pairs.empty() && IsPairLogit(lossFunctionDescription.GetLossFunction()), "Cannot generate pairs, pairs are not empty"); CB_ENSURE( !DataProvider.Targets.empty(), "Pool labels are not provided. Cannot generate pairs." ); Pairs = GeneratePairLogitPairs( DataProvider.QueryIds, DataProvider.Targets, NCatboostOptions::GetMaxPairCount(lossFunctionDescription), Seed); DataProvider.FillQueryPairs(Pairs); } void SetFloatFeatures(const TVector<TFloatFeature>& floatFeatures) override { Y_UNUSED(floatFeatures); CB_ENSURE(false, "Not supported for regular pools"); } void SetTarget(const TVector<float>& target) override { CB_ENSURE(target.size() == DataProvider.Targets.size(), "Error: target size should be equal to line count"); DataProvider.Targets = target; } int GetDocCount() const override { return DataProvider.Targets.size(); } TConstArrayRef<TString> GetLabels() const override { return MakeArrayRef(Labels.data(), Labels.size()); } TConstArrayRef<float> GetWeight() const override { return MakeArrayRef(DataProvider.Weights.data(), DataProvider.Weights.size()); } TConstArrayRef<TGroupId> GetGroupIds() const override { return MakeArrayRef(DataProvider.QueryIds.data(), DataProvider.QueryIds.size()); } // TODO(nikitxskv): Temporary solution until MLTOOLS-140 is implemented. void SetPoolPathAndFormat( const NCB::TPathWithScheme& poolPath, const NCB::TDsvFormatOptions& dsvPoolFormatOptions) { DataProvider.PoolPath = poolPath; DataProvider.DsvPoolFormatOptions = dsvPoolFormatOptions; } void Finish() override; void RegisterFeaturesInFeatureManager(const TVector<TFeatureColumnPtr>& featureColumns) const { for (ui32 featureId = 0; featureId < featureColumns.size(); ++featureId) { if (!FeaturesManager.IsKnown(featureId)) { if (FeatureTypes[featureId] == EFeatureValuesType::Categorical) { FeaturesManager.RegisterDataProviderCatFeature(featureId); } else { FeaturesManager.RegisterDataProviderFloatFeature(featureId); } } } } private: ui32 GetBytesPerFeature(ui32 featureId) const { return FeatureTypes.at(featureId) != EFeatureValuesType::BinarizedFloat ? 4 : 1; } void WriteBinarizedFeatureToBlobImpl(ui32 localIdx, ui32 featureId, ui8 feature); void WriteFloatOrCatFeatureToBlobImpl(ui32 localIdx, ui32 featureId, float feautre); void WriteUnsafeTargetWarningOnce(ui32 localIdx, float value) { if (Y_UNLIKELY(AtomicCas(&UnsafeTargetWarningWritten, true, false))) { const auto rowIndex = Cursor + localIdx; CATBOOST_WARNING_LOG << "Got unsafe target " << LabeledOutput(value) << " at " << LabeledOutput(rowIndex) << '\n'; } } private: inline ui32 GetLineIdx(ui32 localIdx) { return Cursor + localIdx; } inline TString GetFeatureName(ui32 featureId) { return FeatureNames.size() ? FeatureNames[featureId] : ""; } private: TAtomic UnsafeTargetWarningWritten = false; TBinarizedFeaturesManager& FeaturesManager; TDataProvider& DataProvider; bool IsTest; ui32 BuildThreads; TCatFeaturesPerfectHashHelper CatFeaturesPerfectHashHelper; bool ShuffleFlag = false; ui64 Seed = 0; ui32 Cursor = 0; bool IsDone = false; TBinarizedFloatFeaturesMetaInfo BinarizedFeaturesMetaInfo; TVector<TVector<ui8>> FeatureBlobs; TVector<EFeatureValuesType> FeatureTypes; TVector<TVector<float>> Borders; TVector<ENanMode> NanModes; TSet<ui32> IgnoreFeatures; TVector<TString> FeatureNames; TSimpleSharedPtr<TClassificationTargetHelper> TargetHelper; TVector<TPair> Pairs; TVector<TString> Labels; }; void ReadPool( const ::NCB::TPathWithScheme& poolPath, const ::NCB::TPathWithScheme& pairsFilePath, // can be uninited const ::NCB::TPathWithScheme& groupWeightsFilePath, // can be uninited const ::NCatboostOptions::TDsvPoolFormatParams& dsvPoolFormatParams, const TVector<int>& ignoredFeatures, bool verbose, NCB::TTargetConverter* const targetConverter, ::NPar::TLocalExecutor* const localExecutor, TDataProviderBuilder* const poolBuilder); }
Kim2212/catboost
contrib/libs/python/Include/objimpl.h
#pragma once #ifdef USE_PYTHON3 #include <contrib/tools/python3/src/Include/objimpl.h> #else #include <contrib/tools/python/src/Include/objimpl.h> #endif
Kim2212/catboost
catboost/libs/helpers/permutation.h
#pragma once #include "restorable_rng.h" #include <catboost/libs/data_types/groupid.h> #include <util/random/shuffle.h> #include <numeric> TVector<ui64> CreateOrderByKey(const TVector<ui64>& key); template <typename IndexType> TVector<IndexType> InvertPermutation(const TVector<IndexType>& permutation) { TVector<IndexType> result(permutation.size()); for (ui64 i = 0; i < permutation.size(); ++i) { result[permutation[i]] = i; } return result; } template <typename TDataType, typename TRandGen> void Shuffle(const TVector<TGroupId>& queryId, TRandGen& rand, TVector<TDataType>* indices) { if (queryId.empty()) { Shuffle(indices->begin(), indices->end(), rand); return; } TVector<std::pair<int, int>> queryStartAndSize; int docsToPermute = indices->ysize(); for (int docIdx = 0; docIdx < docsToPermute; ++docIdx) { if (docIdx == 0 || queryId[docIdx] != queryId[docIdx - 1]) { queryStartAndSize.emplace_back(docIdx, 1); } else { queryStartAndSize.back().second++; } } Shuffle(queryStartAndSize.begin(), queryStartAndSize.end(), rand); int idxInResult = 0; for (int queryIdx = 0; queryIdx < queryStartAndSize.ysize(); queryIdx++) { const auto& query = queryStartAndSize[queryIdx]; int initialStart = query.first; int resultStart = idxInResult; int size = query.second; for (int doc = 0; doc < size; doc++) { (*indices)[resultStart + doc] = initialStart + doc; } Shuffle(indices->begin() + resultStart, indices->begin() + resultStart + size, rand); idxInResult += size; } }
Kim2212/catboost
util/generic/map.h
#pragma once #include "fwd.h" #include "mapfindptr.h" #include <util/str_stl.h> #include <util/memory/alloc.h> #include <utility> #include <initializer_list> #include <map> #include <memory> template <class K, class V, class Less, class A> class TMap: public std::map<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>>, public TMapOps<TMap<K, V, Less, A>> { using TBase = std::map<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>>; using TSelf = TMap<K, V, Less, A>; using TAllocatorType = typename TBase::allocator_type; using TKeyCompare = typename TBase::key_compare; using TValueType = typename TBase::value_type; public: inline TMap() { } template <typename TAllocParam> inline explicit TMap(TAllocParam* allocator) : TBase(Less(), allocator) { } template <class It> inline TMap(It f, It l) : TBase(f, l) { } inline TMap(std::initializer_list<TValueType> il, const TKeyCompare& comp = TKeyCompare(), const TAllocatorType& alloc = TAllocatorType()) : TBase(il, comp, alloc) { } inline TMap(const TSelf& src) : TBase(src) { } inline TMap(TSelf&& src) noexcept : TBase(std::forward<TSelf>(src)) { } inline TSelf& operator=(const TSelf& src) { TBase::operator=(src); return *this; } inline TSelf& operator=(TSelf&& src) noexcept { TBase::operator=(std::forward<TSelf>(src)); return *this; } Y_PURE_FUNCTION inline bool empty() const noexcept { return TBase::empty(); } inline explicit operator bool() const noexcept { return !this->empty(); } inline bool has(const K& key) const { return this->find(key) != this->end(); } }; template <class K, class V, class Less, class A> class TMultiMap: public std::multimap<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>> { using TBase = std::multimap<K, V, Less, TReboundAllocator<A, std::pair<const K, V>>>; using TSelf = TMultiMap<K, V, Less, A>; using TAllocatorType = typename TBase::allocator_type; using TKeyCompare = typename TBase::key_compare; using TValueType = typename TBase::value_type; public: inline TMultiMap() { } template <typename TAllocParam> inline explicit TMultiMap(TAllocParam* allocator) : TBase(Less(), allocator) { } inline explicit TMultiMap(const Less& less, const TAllocatorType& alloc = TAllocatorType()) : TBase(less, alloc) { } template <class It> inline TMultiMap(It f, It l) : TBase(f, l) { } inline TMultiMap(std::initializer_list<TValueType> il, const TKeyCompare& comp = TKeyCompare(), const TAllocatorType& alloc = TAllocatorType()) : TBase(il, comp, alloc) { } inline TMultiMap(const TSelf& src) : TBase(src) { } inline TMultiMap(TSelf&& src) noexcept { this->swap(src); } inline TSelf& operator=(const TSelf& src) { TBase::operator=(src); return *this; } inline TSelf& operator=(TSelf&& src) noexcept { // Self-move assignment is undefined behavior in the Standard. // This implementation ends up with zero-sized multimap. this->clear(); this->swap(src); return *this; } inline explicit operator bool() const noexcept { return !this->empty(); } Y_PURE_FUNCTION inline bool empty() const noexcept { return TBase::empty(); } inline bool has(const K& key) const { return this->find(key) != this->end(); } };
Kim2212/catboost
catboost/libs/distributed/master.h
#pragma once #include "mappers.h" #include <catboost/libs/algo/learn_context.h> #include <catboost/libs/algo/split.h> #include <catboost/libs/algo/tensor_search_helpers.h> #include <catboost/libs/data/dataset.h> void InitializeMaster(TLearnContext* ctx); void FinalizeMaster(TLearnContext* ctx); void MapBuildPlainFold(const TDataset& trainData, TLearnContext* ctx); void MapTensorSearchStart(TLearnContext* ctx); void MapBootstrap(TLearnContext* ctx); void MapCalcScore(double scoreStDev, int depth, TCandidateList* candidateList, TLearnContext* ctx); void MapRemoteCalcScore(double scoreStDev, int depth, TCandidateList* candidateList, TLearnContext* ctx); void MapPairwiseCalcScore(double scoreStDev, TCandidateList* candidateList, TLearnContext* ctx); void MapRemotePairwiseCalcScore(double scoreStDev, TCandidateList* candidateList, TLearnContext* ctx); void MapSetIndices(const TCandidateInfo& bestSplitCandidate, TLearnContext* ctx); int MapGetRedundantSplitIdx(TLearnContext* ctx); void MapCalcErrors(TLearnContext* ctx); template <typename TError> void MapSetDerivatives(TLearnContext* ctx); template <typename TError> void MapSetApproxesSimple(const TSplitTree& splitTree, TLearnContext* ctx); template <typename TError> void MapSetApproxesMulti(const TSplitTree& splitTree, TLearnContext* ctx); namespace { template <typename TMapper> static TVector<typename TMapper::TOutput> ApplyMapper(int workerCount, TObj<NPar::IEnvironment> environment, const typename TMapper::TInput& value = typename TMapper::TInput()) { NPar::TJobDescription job; TVector<typename TMapper::TInput> mapperInput(1); mapperInput[0] = value; NPar::Map(&job, new TMapper(), &mapperInput); job.SeparateResults(workerCount); NPar::TJobExecutor exec(&job, environment); TVector<typename TMapper::TOutput> mapperOutput; exec.GetResultVec(&mapperOutput); return mapperOutput; } template <typename TError, typename TApproxDefs> void MapSetApproxes(const TSplitTree& splitTree, TLearnContext* ctx) { static_assert(TError::IsCatboostErrorFunction, "TError is not a CatBoost error function class"); using namespace NCatboostDistributed; using TSum = typename TApproxDefs::TSumType; using TPairwiseBuckets = typename TApproxDefs::TPairwiseBuckets; using TBucketUpdater = typename TApproxDefs::TBucketUpdater; using TDeltaUpdater = typename TApproxDefs::TDeltaUpdater; Y_ASSERT(ctx->Params.SystemOptions->IsMaster()); const int workerCount = ctx->RootEnvironment->GetSlaveCount(); ApplyMapper<TCalcApproxStarter>(workerCount, ctx->SharedTrainData, TEnvelope<TSplitTree>(splitTree)); const int gradientIterations = ctx->Params.ObliviousTreeOptions->LeavesEstimationIterations; const int approxDimension = ctx->LearnProgress.ApproxDimension; TVector<TSum> buckets(splitTree.GetLeafCount(), TSum(gradientIterations, approxDimension, TError::GetHessianType())); for (int it = 0; it < gradientIterations; ++it) { TPairwiseBuckets pairwiseBuckets; TApproxDefs::SetPairwiseBucketsSize(splitTree.GetLeafCount(), &pairwiseBuckets); TVector<typename TBucketUpdater::TOutput> bucketsFromAllWorkers = ApplyMapper<TBucketUpdater>(workerCount, ctx->SharedTrainData); // reduce across workers for (int workerIdx = 0; workerIdx < workerCount; ++workerIdx) { const auto& workerBuckets = bucketsFromAllWorkers[workerIdx].Data.first; for (int leafIdx = 0; leafIdx < buckets.ysize(); ++leafIdx) { if (ctx->Params.ObliviousTreeOptions->LeavesEstimationMethod == ELeavesEstimation::Gradient) { buckets[leafIdx].AddDerWeight(workerBuckets[leafIdx].SumDerHistory[it], workerBuckets[leafIdx].SumWeights, it); } else { Y_ASSERT(ctx->Params.ObliviousTreeOptions->LeavesEstimationMethod == ELeavesEstimation::Newton); buckets[leafIdx].AddDerDer2(workerBuckets[leafIdx].SumDerHistory[it], workerBuckets[leafIdx].SumDer2History[it], it); } } TApproxDefs::AddPairwiseBuckets(bucketsFromAllWorkers[workerIdx].Data.second, &pairwiseBuckets); } // calc model and update approx deltas on workers ApplyMapper<TDeltaUpdater>(workerCount, ctx->SharedTrainData, TEnvelope<std::pair<TVector<TSum>, TPairwiseBuckets>>({buckets, pairwiseBuckets})); } ApplyMapper<TApproxUpdater>(workerCount, ctx->SharedTrainData); } template <typename TError> struct TSetApproxesSimpleDefs { using TSumType = TSum; using TPairwiseBuckets = TArray2D<double>; using TBucketUpdater = NCatboostDistributed::TBucketSimpleUpdater<TError>; using TDeltaUpdater = NCatboostDistributed::TDeltaSimpleUpdater; static void SetPairwiseBucketsSize(size_t leafCount, TPairwiseBuckets* pairwiseBuckets) { pairwiseBuckets->SetSizes(leafCount, leafCount); pairwiseBuckets->FillZero(); } static void AddPairwiseBuckets(const TPairwiseBuckets& increment, TPairwiseBuckets* total) { Y_ASSERT(increment.GetXSize() == total->GetXSize() && increment.GetYSize() == total->GetYSize()); for (size_t winnerIdx = 0; winnerIdx < increment.GetYSize(); ++winnerIdx) { for (size_t loserIdx = 0; loserIdx < increment.GetXSize(); ++loserIdx) { (*total)[winnerIdx][loserIdx] += increment[winnerIdx][loserIdx]; } } } }; template <typename TError> struct TSetApproxesMultiDefs { using TSumType = TSumMulti; using TPairwiseBuckets = NCatboostDistributed::TUnusedInitializedParam; using TBucketUpdater = NCatboostDistributed::TBucketMultiUpdater<TError>; using TDeltaUpdater = NCatboostDistributed::TDeltaMultiUpdater; static void SetPairwiseBucketsSize(size_t /*leafCount*/, TPairwiseBuckets* /*pairwiseBuckets*/) {} static void AddPairwiseBuckets(const TPairwiseBuckets& /*increment*/, TPairwiseBuckets* /*total*/) {} }; } // anonymous namespace template <typename TError> void MapSetApproxesSimple(const TSplitTree& splitTree, TLearnContext* ctx) { MapSetApproxes<TError, TSetApproxesSimpleDefs<TError>>(splitTree, ctx); } template <typename TError> void MapSetApproxesMulti(const TSplitTree& splitTree, TLearnContext* ctx) { MapSetApproxes<TError, TSetApproxesMultiDefs<TError>>(splitTree, ctx); } template <typename TError> void MapSetDerivatives(TLearnContext* ctx) { static_assert(TError::IsCatboostErrorFunction, "TError is not a CatBoost error function class"); using namespace NCatboostDistributed; Y_ASSERT(ctx->Params.SystemOptions->IsMaster()); ApplyMapper<TDerivativeSetter<TError>>(ctx->RootEnvironment->GetSlaveCount(), ctx->SharedTrainData); }
Kim2212/catboost
contrib/libs/python/Include/abstract.h
#pragma once #ifdef USE_PYTHON3 #include <contrib/tools/python3/src/Include/abstract.h> #else #include <contrib/tools/python/src/Include/abstract.h> #endif
adricatena/I2-puertoSerie
Actividad2_envio/ventanaprincipal.h
#ifndef VENTANAPRINCIPAL_H #define VENTANAPRINCIPAL_H #include <QDialog> #include <qextserialport.h> #include <QFileDialog> #include <QMessageBox> #include <QSettings> #include <QApplication> #include <QFile> #include <QTextStream> #include "portcfg.h" #include "ui_portcfg.h" namespace Ui { class VentanaPrincipal; } class VentanaPrincipal : public QDialog { Q_OBJECT public: explicit VentanaPrincipal(QWidget *parent = 0); ~VentanaPrincipal(); QextSerialPort * puertoSerie; portCfg *cfg; private slots: void on_btnSeleccionArchivo_clicked(); void on_btnConectar_clicked(); void on_btnDesconectar_clicked(); void on_btnSalir_clicked(); void on_btnEnviar_clicked(); public slots: void DatosRecibidos(); private: Ui::VentanaPrincipal *ui; QString nombreArchivo; QMessageBox msj; bool permiso; QFile archivo; QByteArray binario; }; #endif // VENTANAPRINCIPAL_H
adricatena/I2-puertoSerie
Actividad2_recibe-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/ui_ventanaconfirmacion.h
<filename>Actividad2_recibe-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/ui_ventanaconfirmacion.h /******************************************************************************** ** Form generated from reading UI file 'ventanaconfirmacion.ui' ** ** Created: Wed 5. Dec 11:11:26 2012 ** by: Qt User Interface Compiler version 4.8.1 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ #ifndef UI_VENTANACONFIRMACION_H #define UI_VENTANACONFIRMACION_H #include <QtCore/QVariant> #include <QtGui/QAction> #include <QtGui/QApplication> #include <QtGui/QButtonGroup> #include <QtGui/QDialog> #include <QtGui/QHBoxLayout> #include <QtGui/QHeaderView> #include <QtGui/QLabel> #include <QtGui/QPushButton> #include <QtGui/QSpacerItem> #include <QtGui/QVBoxLayout> #include <QtGui/QWidget> QT_BEGIN_NAMESPACE class Ui_VentanaConfirmacion { public: QWidget *widget; QVBoxLayout *verticalLayout; QHBoxLayout *horizontalLayout_2; QSpacerItem *horizontalSpacer_2; QLabel *labTituloConfirmacion; QSpacerItem *horizontalSpacer_3; QHBoxLayout *horizontalLayout; QPushButton *btnAceptar; QSpacerItem *horizontalSpacer; QPushButton *btnCancelar; void setupUi(QDialog *VentanaConfirmacion) { if (VentanaConfirmacion->objectName().isEmpty()) VentanaConfirmacion->setObjectName(QString::fromUtf8("VentanaConfirmacion")); VentanaConfirmacion->resize(244, 79); widget = new QWidget(VentanaConfirmacion); widget->setObjectName(QString::fromUtf8("widget")); widget->setGeometry(QRect(10, 10, 221, 55)); verticalLayout = new QVBoxLayout(widget); verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); verticalLayout->setContentsMargins(0, 0, 0, 0); horizontalLayout_2 = new QHBoxLayout(); horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_2->addItem(horizontalSpacer_2); labTituloConfirmacion = new QLabel(widget); labTituloConfirmacion->setObjectName(QString::fromUtf8("labTituloConfirmacion")); horizontalLayout_2->addWidget(labTituloConfirmacion); horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_2->addItem(horizontalSpacer_3); verticalLayout->addLayout(horizontalLayout_2); horizontalLayout = new QHBoxLayout(); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); btnAceptar = new QPushButton(widget); btnAceptar->setObjectName(QString::fromUtf8("btnAceptar")); horizontalLayout->addWidget(btnAceptar); horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout->addItem(horizontalSpacer); btnCancelar = new QPushButton(widget); btnCancelar->setObjectName(QString::fromUtf8("btnCancelar")); horizontalLayout->addWidget(btnCancelar); verticalLayout->addLayout(horizontalLayout); retranslateUi(VentanaConfirmacion); QMetaObject::connectSlotsByName(VentanaConfirmacion); } // setupUi void retranslateUi(QDialog *VentanaConfirmacion) { VentanaConfirmacion->setWindowTitle(QApplication::translate("VentanaConfirmacion", "Dialog", 0, QApplication::UnicodeUTF8)); labTituloConfirmacion->setText(QApplication::translate("VentanaConfirmacion", "\302\277Desea recibir un archivo?", 0, QApplication::UnicodeUTF8)); btnAceptar->setText(QApplication::translate("VentanaConfirmacion", "Aceptar", 0, QApplication::UnicodeUTF8)); btnCancelar->setText(QApplication::translate("VentanaConfirmacion", "Cancelar", 0, QApplication::UnicodeUTF8)); } // retranslateUi }; namespace Ui { class VentanaConfirmacion: public Ui_VentanaConfirmacion {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_VENTANACONFIRMACION_H
adricatena/I2-puertoSerie
Actividad2_recibe-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug/ui_ventanaarchivoexistente.h
/******************************************************************************** ** Form generated from reading UI file 'ventanaarchivoexistente.ui' ** ** Created: Wed 5. Dec 11:11:27 2012 ** by: Qt User Interface Compiler version 4.8.1 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ #ifndef UI_VENTANAARCHIVOEXISTENTE_H #define UI_VENTANAARCHIVOEXISTENTE_H #include <QtCore/QVariant> #include <QtGui/QAction> #include <QtGui/QApplication> #include <QtGui/QButtonGroup> #include <QtGui/QCheckBox> #include <QtGui/QDialog> #include <QtGui/QHBoxLayout> #include <QtGui/QHeaderView> #include <QtGui/QLabel> #include <QtGui/QLineEdit> #include <QtGui/QPushButton> #include <QtGui/QSpacerItem> #include <QtGui/QVBoxLayout> #include <QtGui/QWidget> QT_BEGIN_NAMESPACE class Ui_VentanaArchivoExistente { public: QWidget *widget; QVBoxLayout *verticalLayout; QHBoxLayout *horizontalLayout_4; QSpacerItem *horizontalSpacer; QLabel *labTituloArchivoExistente; QSpacerItem *horizontalSpacer_2; QHBoxLayout *horizontalLayout_5; QLabel *labTitulo2ArchivoExistente; QSpacerItem *horizontalSpacer_3; QHBoxLayout *horizontalLayout_3; QSpacerItem *horizontalSpacer_6; QCheckBox *checkBoxSi; QSpacerItem *horizontalSpacer_7; QCheckBox *checkBoxNo; QSpacerItem *horizontalSpacer_9; QHBoxLayout *horizontalLayout; QLabel *labTituloRenombrar; QLineEdit *leNombreArchivo; QSpacerItem *horizontalSpacer_4; QHBoxLayout *horizontalLayout_2; QPushButton *btnAceptar; QSpacerItem *horizontalSpacer_5; QPushButton *btnCancelar; void setupUi(QDialog *VentanaArchivoExistente) { if (VentanaArchivoExistente->objectName().isEmpty()) VentanaArchivoExistente->setObjectName(QString::fromUtf8("VentanaArchivoExistente")); VentanaArchivoExistente->resize(269, 161); widget = new QWidget(VentanaArchivoExistente); widget->setObjectName(QString::fromUtf8("widget")); widget->setGeometry(QRect(10, 10, 249, 139)); verticalLayout = new QVBoxLayout(widget); verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); verticalLayout->setContentsMargins(0, 0, 0, 0); horizontalLayout_4 = new QHBoxLayout(); horizontalLayout_4->setObjectName(QString::fromUtf8("horizontalLayout_4")); horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_4->addItem(horizontalSpacer); labTituloArchivoExistente = new QLabel(widget); labTituloArchivoExistente->setObjectName(QString::fromUtf8("labTituloArchivoExistente")); horizontalLayout_4->addWidget(labTituloArchivoExistente); horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_4->addItem(horizontalSpacer_2); verticalLayout->addLayout(horizontalLayout_4); horizontalLayout_5 = new QHBoxLayout(); horizontalLayout_5->setObjectName(QString::fromUtf8("horizontalLayout_5")); labTitulo2ArchivoExistente = new QLabel(widget); labTitulo2ArchivoExistente->setObjectName(QString::fromUtf8("labTitulo2ArchivoExistente")); horizontalLayout_5->addWidget(labTitulo2ArchivoExistente); horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_5->addItem(horizontalSpacer_3); verticalLayout->addLayout(horizontalLayout_5); horizontalLayout_3 = new QHBoxLayout(); horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3")); horizontalSpacer_6 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_3->addItem(horizontalSpacer_6); checkBoxSi = new QCheckBox(widget); checkBoxSi->setObjectName(QString::fromUtf8("checkBoxSi")); checkBoxSi->setChecked(true); horizontalLayout_3->addWidget(checkBoxSi); horizontalSpacer_7 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_3->addItem(horizontalSpacer_7); checkBoxNo = new QCheckBox(widget); checkBoxNo->setObjectName(QString::fromUtf8("checkBoxNo")); horizontalLayout_3->addWidget(checkBoxNo); horizontalSpacer_9 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_3->addItem(horizontalSpacer_9); verticalLayout->addLayout(horizontalLayout_3); horizontalLayout = new QHBoxLayout(); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); labTituloRenombrar = new QLabel(widget); labTituloRenombrar->setObjectName(QString::fromUtf8("labTituloRenombrar")); horizontalLayout->addWidget(labTituloRenombrar); leNombreArchivo = new QLineEdit(widget); leNombreArchivo->setObjectName(QString::fromUtf8("leNombreArchivo")); horizontalLayout->addWidget(leNombreArchivo); horizontalSpacer_4 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout->addItem(horizontalSpacer_4); verticalLayout->addLayout(horizontalLayout); horizontalLayout_2 = new QHBoxLayout(); horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); btnAceptar = new QPushButton(widget); btnAceptar->setObjectName(QString::fromUtf8("btnAceptar")); horizontalLayout_2->addWidget(btnAceptar); horizontalSpacer_5 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalLayout_2->addItem(horizontalSpacer_5); btnCancelar = new QPushButton(widget); btnCancelar->setObjectName(QString::fromUtf8("btnCancelar")); horizontalLayout_2->addWidget(btnCancelar); verticalLayout->addLayout(horizontalLayout_2); retranslateUi(VentanaArchivoExistente); QMetaObject::connectSlotsByName(VentanaArchivoExistente); } // setupUi void retranslateUi(QDialog *VentanaArchivoExistente) { VentanaArchivoExistente->setWindowTitle(QApplication::translate("VentanaArchivoExistente", "Dialog", 0, QApplication::UnicodeUTF8)); labTituloArchivoExistente->setText(QApplication::translate("VentanaArchivoExistente", "Archivo existente", 0, QApplication::UnicodeUTF8)); labTitulo2ArchivoExistente->setText(QApplication::translate("VentanaArchivoExistente", "\302\277Desea sobre escribirlo?", 0, QApplication::UnicodeUTF8)); checkBoxSi->setText(QApplication::translate("VentanaArchivoExistente", "Si", 0, QApplication::UnicodeUTF8)); checkBoxNo->setText(QApplication::translate("VentanaArchivoExistente", "No", 0, QApplication::UnicodeUTF8)); labTituloRenombrar->setText(QApplication::translate("VentanaArchivoExistente", "Renombrar :", 0, QApplication::UnicodeUTF8)); btnAceptar->setText(QApplication::translate("VentanaArchivoExistente", "Aceptar", 0, QApplication::UnicodeUTF8)); btnCancelar->setText(QApplication::translate("VentanaArchivoExistente", "Cancelar", 0, QApplication::UnicodeUTF8)); } // retranslateUi }; namespace Ui { class VentanaArchivoExistente: public Ui_VentanaArchivoExistente {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_VENTANAARCHIVOEXISTENTE_H
adricatena/I2-puertoSerie
Actividad2_recibe/ventanaprincipal.h
<filename>Actividad2_recibe/ventanaprincipal.h #ifndef VENTANAPRINCIPAL_H #define VENTANAPRINCIPAL_H #include <QDialog> #include "portcfg.h" #include "ui_portcfg.h" #include "ventanaconfirmacion.h" #include "ui_ventanaconfirmacion.h" #include "ventanaarchivoexistente.h" #include "ui_ventanaarchivoexistente.h" #include <qextserialport.h> #include <QextSerialEnumerator.h> #include <QFile> #include <QFileDialog> #include <QMessageBox> #include <QSettings> #include <QApplication> namespace Ui { class VentanaPrincipal; } class VentanaPrincipal : public QDialog { Q_OBJECT public: explicit VentanaPrincipal(QWidget *parent = 0); ~VentanaPrincipal(); QextSerialPort * puertoSerie; void confirmacion(); portCfg *cfg; private slots: void on_btnConectar_clicked(); void on_btnDesconectar_clicked(); void on_btnSalir_clicked(); public slots: void DatosRecibidos(); private: Ui::VentanaPrincipal *ui; bool conectado; char v; VentanaConfirmacion *ventana; VentanaArchivoExistente *ventanaExistente; QMessageBox msj; QSettings *configuracion; }; #endif // VENTANAPRINCIPAL_H