double mctlib::mt2neg(const double v1[4],const double v2[4] ,const double ptm[2],const double mxlo) { // Non boost-corrected analytical mt2 double m1sqr = pow(v1[0],2)-pow(v1[1],2)-pow(v1[2],2)-pow(v1[3],2); double m2sqr = pow(v2[0],2)-pow(v2[1],2)-pow(v2[2],2)-pow(v2[3],2); double chisqr = pow(mxlo,2); double m1 = sqrt(fmax(m1sqr,0.0)); double m2 = sqrt(fmax(m2sqr,0.0)); double chi = mxlo; double qtest[3] = {0.0,ptm[0]-(chi/m1)*v1[1],ptm[1]-(chi/m1)*v1[2]}; qtest[0] = sqrt(chisqr+pow(qtest[1],2)+pow(qtest[2],2)); double ptest[3] = {0.0,ptm[0]-(chi/m2)*v2[1],ptm[1]-(chi/m2)*v2[2]}; ptest[0] = sqrt(chisqr+pow(ptest[1],2)+pow(ptest[2],2)); double et1 = sqrt(fmax(v1[0]*v1[0]-v1[3]*v1[3],0.0)); double et2 = sqrt(fmax(v2[0]*v2[0]-v2[3]*v2[3],0.0)); double bq[3] = {et2+qtest[0],v2[1]+qtest[1],v2[2]+qtest[2]}; double ap[3] = {et1+ptest[0],v1[1]+ptest[1],v1[2]+ptest[2]}; // Use unbalanced solutions if (pow(m1+chi,2)>=pow(bq[0],2)-pow(bq[1],2)-pow(bq[2],2)) { return m1+chi; } else if (pow(m2+chi,2)>=pow(ap[0],2)-pow(ap[1],2)-pow(ap[2],2)) { return m2+chi; } // Else use balanced solution double mctminsqr = pow(mct(v1,v2),2); double mdmin = mctminmt2(mctminsqr,m1sqr,m2sqr,chisqr); return fmax(fmax(mdmin,m1+chi),m2+chi); }
double mctlib::mcx(const double v1[4],const double v2[4] ,const double vds[4],const double ptm[2]) { // v1, v2 are the 4-vectors of the two aggregated decay products // vds is the 4-vector of the downstream objects (excluding v1 and v2) // ptm is the pTmiss 2-vector {pxmiss,pymiss} double ptus[2] = {-v1[1]-v2[1]-vds[1]-ptm[0],-v1[2]-v2[2]-vds[2]-ptm[1]}; double pb = sqrt(pow(ptus[0],2)+pow(ptus[1],2)); if (pb==0) { return mct(v1,v2); } else { // Transform to new basis in transverse plane // ISR goes in +ve x direction double vb1[4] = {v1[0],(v1[1]*ptus[0]+v1[2]*ptus[1])/pb ,(v1[1]*ptus[1]-v1[2]*ptus[0])/pb,v1[3]}; double vb2[4] = {v2[0],(v2[1]*ptus[0]+v2[2]*ptus[1])/pb ,(v2[1]*ptus[1]-v2[2]*ptus[0])/pb,v2[3]}; double vex1 = sqrt(fmax(pow(vb1[0],2)-pow(vb1[2],2)-pow(vb1[3],2),0.0)); double vex2 = sqrt(fmax(pow(vb2[0],2)-pow(vb2[2],2)-pow(vb2[3],2),0.0)); return sqrt(fmax(pow(vex1+vex2,2)-pow(vb1[1]-vb2[1],2),0.0)); } }
int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "%s [mct|vst]\n", argv[0]); exit(1); } if (!FIPS_mode_set(1)) { do_print_errors(); exit(1); } FIPS_rand_reset(); if (!FIPS_rand_test_mode()) { fprintf(stderr, "Error setting PRNG test mode\n"); do_print_errors(); exit(1); } if (!strcmp(argv[1], "mct")) mct(); else if (!strcmp(argv[1], "vst")) vst(); else { fprintf(stderr, "Don't know how to %s.\n", argv[1]); exit(1); } return 0; }
static int handle_graphic_(t_ctrl *c, t_jm_list *cli) { ((t_handler*)cli->data)->t = GFX; ((t_handler*)cli->data)->handler = handle_gfx; msz(c, cli); sgt(c, cli); mct(c, cli); tna(c, cli); list_eggs_and_players(c, cli); return (1); }
void update_bct_graphic(t_env *e) { int i; i = 0; while (i < MAX_FD) { if (e->fd_type[i] == FD_GRAPHICAL_SERVER) mct(e, i, NULL); i = i + 1; } }
void gfx_connection(t_env *e, int fd) { t_iterator iter_t; t_team *t; e->fds[fd].type = FD_GFX_CLIENT; ft_lst_pushend(e->gfx_lst, gfx_new(fd)); printf("Client #%d: Connected as GFX\n", fd); msz(e, fd); sgt(e, fd); mct(e, fd); tna(e, fd); iter_t = NULL; while ((t = (t_team *)ft_lst_iter_next_content(e->team, &iter_t))) notify_bot_for_connected_gfx(e, fd, t); }
void cmd_incantation(t_server *serv, int actual, char *buff) { int i; i = 0; (void)buff; if (!verif_lvl_tb(serv, actual)) { if (serv->gfx.sock) { pie(serv->gfx.sock, serv->clients[actual].x, serv->clients[actual].y, 0); while (i < serv->connected) plv(serv->gfx.sock, &serv->clients[i++]); mct(serv->gfx.sock, serv); } write(serv->clients[actual].sock, "ko\n", 3); return ; } lvl_up_player(serv, actual, serv->clients[actual].x, serv->clients[actual].y); }
static int selfTest( void ) { #if 0 /* ECB */ static const BYTE FAR_BSS mctECBKey[] = \ { 0x8D, 0x2E, 0x60, 0x36, 0x5F, 0x17, 0xC7, 0xDF, 0x10, 0x40, 0xD7, 0x50, 0x1B, 0x4A, 0x7B, 0x5A }; static const BYTE FAR_BSS mctECBPT[] = \ { 0x59, 0xB5, 0x08, 0x8E, 0x6D, 0xAD, 0xC3, 0xAD, 0x5F, 0x27, 0xA4, 0x60, 0x87, 0x2D, 0x59, 0x29 }; /* CBC */ static const BYTE FAR_BSS mctCBCKey[] = \ { 0x9D, 0xC2, 0xC8, 0x4A, 0x37, 0x85, 0x0C, 0x11, 0x69, 0x98, 0x18, 0x60, 0x5F, 0x47, 0x95, 0x8C }; static const BYTE FAR_BSS mctCBCIV[] = \ { 0x25, 0x69, 0x53, 0xB2, 0xFE, 0xAB, 0x2A, 0x04, 0xAE, 0x01, 0x80, 0xD8, 0x33, 0x5B, 0xBE, 0xD6 }; static const BYTE FAR_BSS mctCBCPT[] = \ { 0x2E, 0x58, 0x66, 0x92, 0xE6, 0x47, 0xF5, 0x02, 0x8E, 0xC6, 0xFA, 0x47, 0xA5, 0x5A, 0x2A, 0xAB }; /* OFB */ static const BYTE FAR_BSS mctOFBKey[] = \ { 0xB1, 0x1E, 0x4E, 0xCA, 0xE2, 0xE7, 0x1E, 0x14, 0x14, 0x5D, 0xD7, 0xDB, 0x26, 0x35, 0x65, 0x2F }; static const BYTE FAR_BSS mctOFBIV[] = \ { 0xAD, 0xD3, 0x2B, 0xF8, 0x20, 0x4C, 0x33, 0x33, 0x9C, 0x54, 0xCD, 0x58, 0x58, 0xEE, 0x0D, 0x13 }; static const BYTE FAR_BSS mctOFBPT[] = \ { 0x73, 0x20, 0x49, 0xE8, 0x9D, 0x74, 0xFC, 0xE7, 0xC5, 0xA4, 0x96, 0x64, 0x04, 0x86, 0x8F, 0xA6 }; /* CFB-128 */ static const BYTE FAR_BSS mctCFBKey[] = \ { 0x71, 0x15, 0x11, 0x93, 0x1A, 0x15, 0x62, 0xEA, 0x73, 0x29, 0x0A, 0x8B, 0x0A, 0x37, 0xA3, 0xB4 }; static const BYTE FAR_BSS mctCFBIV[] = \ { 0x9D, 0xCE, 0x23, 0xFD, 0x2D, 0xF5, 0x36, 0x0F, 0x79, 0x9C, 0xF1, 0x79, 0x84, 0xE4, 0x7C, 0x8D }; static const BYTE FAR_BSS mctCFBPT[] = \ { 0xF0, 0x66, 0xBE, 0x4B, 0xD6, 0x71, 0xEB, 0xC1, 0xC4, 0xCF, 0x3C, 0x00, 0x8E, 0xF2, 0xCF, 0x18 }; #endif /* 0 */ const CAPABILITY_INFO *capabilityInfo = getAESCapability(); BYTE keyData[ AES_EXPANDED_KEYSIZE + 8 ]; int i, status; /* The AES code requires 16-byte alignment for data structures, before we try anything else we make sure that the compiler voodoo required to handle this has worked */ if( aes_test_alignment_detection( 16 ) != EXIT_SUCCESS ) return( CRYPT_ERROR_FAILED ); for( i = 0; i < sizeof( testAES ) / sizeof( AES_TEST ); i++ ) { status = testCipher( capabilityInfo, keyData, testAES[ i ].key, testAES[ i ].keySize, testAES[ i ].plaintext, testAES[ i ].ciphertext ); if( cryptStatusError( status ) ) return( status ); } #if 0 /* OK */ staticInitContext( &contextInfo, CONTEXT_CONV, capabilityInfo, &contextData, sizeof( CONV_INFO ), keyData ); status = mct( &contextInfo, capabilityInfo, mctECBKey, 16, NULL, mctECBPT ); staticDestroyContext( &contextInfo ); if( cryptStatusError( status ) ) return( CRYPT_ERROR_FAILED ); #endif #if 0 /* OK */ staticInitContext( &contextInfo, CONTEXT_CONV, capabilityInfo, &contextData, sizeof( CONV_INFO ), keyData ); status = mct( &contextInfo, capabilityInfo, mctCBCKey, 16, mctCBCIV, mctCBCPT ); staticDestroyContext( &contextInfo ); if( cryptStatusError( status ) ) return( CRYPT_ERROR_FAILED ); #endif return( CRYPT_OK ); }
double mctlib::mctcorr(const double v1[4],const double v2[4] ,const double vds[4],const double ptm[2] ,const double ecm,const double mxlo) { // v1, v2 are the 4-vectors of the two aggregated decay products // vds is the 4-vector of the downstream objects (excluding v1 and v2) // ptm is the pTmiss 2-vector {pxmiss,pymiss} // ecm is the centre-of-mass energy (D=14TeV) // mxlo is a lower bound on the mass of each invisible decay product (D=0) double ptus[2] = {-v1[1]-v2[1]-vds[1]-ptm[0],-v1[2]-v2[2]-vds[2]-ptm[1]}; m_pb = sqrt(pow(ptus[0],2)+pow(ptus[1],2)); if (m_pb==0) { return mct(v1,v2); } else { // Transform to new basis in transverse plane // ISR goes in +ve x direction double vb1[4] = {v1[0],(v1[1]*ptus[0]+v1[2]*ptus[1])/m_pb ,(v1[1]*ptus[1]-v1[2]*ptus[0])/m_pb,v1[3]}; double vb2[4] = {v2[0],(v2[1]*ptus[0]+v2[2]*ptus[1])/m_pb ,(v2[1]*ptus[1]-v2[2]*ptus[0])/m_pb,v2[3]}; double vey1 = sqrt(fmax(pow(vb1[0],2)-pow(vb1[1],2)-pow(vb1[3],2),0.0)); double vey2 = sqrt(fmax(pow(vb2[0],2)-pow(vb2[1],2)-pow(vb2[3],2),0.0)); double ax = vb1[1]*vey2+vb2[1]*vey1; // Boost v1 and v2 with Ecm // v1 and v2 were boosted in -ve x direction, // so to correct we boost v1 and v2 in +ve x direction double beta = m_pb/ecm; double gamma = 1.0/sqrt(1.0-beta*beta); double vb1p[4] = {gamma*(vb1[0]+vb1[1]*beta),gamma*(vb1[1]+vb1[0]*beta) ,vb1[2],vb1[3]}; double vb2p[4] = {gamma*(vb2[0]+vb2[1]*beta),gamma*(vb2[1]+vb2[0]*beta) ,vb2[2],vb2[3]}; double vey1p = sqrt(fmax(pow(vb1p[0],2)-pow(vb1p[1],2) -pow(vb1p[3],2),0.0)); double vey2p = sqrt(fmax(pow(vb2p[0],2)-pow(vb2p[1],2) -pow(vb2p[3],2),0.0)); double axecm = vb1p[1]*vey2p+vb2p[1]*vey1p; m_mctecm = mct(vb1p,vb2p); // Boost v1 and v2 with e0 // v1 and v2 were boosted in -ve x direction, // so to correct we boost v1 and v2 in +ve x direction beta = m_pb/(v1[0]+v2[0]+vds[0] +sqrt(pow(ptm[0],2)+pow(ptm[1],2)+4.0*pow(mxlo,2))); gamma = 1.0/sqrt(1.0-beta*beta); double vb1pp[4] = {gamma*(vb1[0]+vb1[1]*beta),gamma*(vb1[1]+vb1[0]*beta) ,vb1[2],vb1[3]}; double vb2pp[4] = {gamma*(vb2[0]+vb2[1]*beta),gamma*(vb2[1]+vb2[0]*beta) ,vb2[2],vb2[3]}; double vey1pp = sqrt(fmax(pow(vb1pp[0],2)-pow(vb1pp[1],2) -pow(vb1pp[3],2),0.0)); double vey2pp = sqrt(fmax(pow(vb2pp[0],2)-pow(vb2pp[1],2) -pow(vb2pp[3],2),0.0)); double axehat = vb1pp[1]*vey2pp+vb2pp[1]*vey1pp; m_mctehat = mct(vb1pp,vb2pp); if ( (ax>=0) || (axecm>=0) ) { return m_mctecm; } else { if (axehat<0) { return m_mctehat; } else { return sqrt(fmax(pow(vey1+vey2,2)-pow(vb1[2]-vb2[2],2),0.0)); } } } }
static void vst(FILE *in, FILE *out) { unsigned char *key = NULL; unsigned char *v = NULL; unsigned char *dt = NULL; unsigned char ret[16]; char buf[1024]; char lbuf[1024]; uint8_t seed[1024]; char *keyword, *value; long i, keylen; struct session_op session = { .rng = CRYPTO_ANSI_CPRNG, .key = seed }; struct crypt_op op = { .dst = ret, .len = 16 }; keylen = 0; while(fgets(buf,sizeof buf,in) != NULL) { fputs(buf,out); if(!strncmp(buf,"[AES 128-Key]", 13)) keylen = 16; else if(!strncmp(buf,"[AES 192-Key]", 13)) keylen = 24; else if(!strncmp(buf,"[AES 256-Key]", 13)) keylen = 32; if (!parse_line(&keyword, &value, lbuf, buf)) continue; if(!strcmp(keyword,"Key")) { key=hex2bin_m(value,&i); if (i != keylen) { fprintf(stderr, "Invalid key length, expecting %ld\n", keylen); return; } } else if(!strcmp(keyword,"DT")) { dt=hex2bin_m(value,&i); if (i != 16) { fprintf(stderr, "Invalid DT length\n"); return; } } else if(!strcmp(keyword,"V")) { v=hex2bin_m(value,&i); if (i != 16) { fprintf(stderr, "Invalid V length\n"); return; } if (!key || !dt) { fprintf(stderr, "Missing key or DT\n"); return; } session.keylen = build_seed(seed, v, key, dt, keylen); if (session.keylen > sizeof(seed)/sizeof(*seed)) { fprintf(stderr, "Seed buffer overrun\n"); return; } if (!cryptodev_op(session,op)) { fprintf(stderr, "Error getting PRNG value\n"); return; } OutputValue("R", ret, 16, out, 0); OPENSSL_free(key); key = NULL; OPENSSL_free(dt); dt = NULL; OPENSSL_free(v); v = NULL; } } } static void mct(FILE *in, FILE *out) { unsigned char *key = NULL; unsigned char *v = NULL; unsigned char *dt = NULL; unsigned char ret[16]; char buf[1024]; char lbuf[1024]; uint8_t seed[1024]; char *keyword, *value; long i, keylen; int cryptofd; struct session_op session = { .rng = CRYPTO_ANSI_CPRNG, .key = seed }; struct crypt_op op = { .dst = ret, .len = 16 }; keylen = 0; while(fgets(buf,sizeof buf,in) != NULL) { fputs(buf,out); if(!strncmp(buf,"[AES 128-Key]", 13)) keylen = 16; else if(!strncmp(buf,"[AES 192-Key]", 13)) keylen = 24; else if(!strncmp(buf,"[AES 256-Key]", 13)) keylen = 32; if (!parse_line(&keyword, &value, lbuf, buf)) continue; if(!strcmp(keyword,"Key")) { key=hex2bin_m(value,&i); if (i != keylen) { fprintf(stderr, "Invalid key length, expecting %ld\n", keylen); return; } } else if(!strcmp(keyword,"DT")) { dt=hex2bin_m(value,&i); if (i != 16) { fprintf(stderr, "Invalid DT length\n"); return; } } else if(!strcmp(keyword,"V")) { v=hex2bin_m(value,&i); if (i != 16) { fprintf(stderr, "Invalid V length\n"); return; } if (!key || !dt) { fprintf(stderr, "Missing key or DT\n"); return; } session.keylen = build_seed(seed, v, key, dt, keylen); if (session.keylen > sizeof(seed)/sizeof(*seed)) { fprintf(stderr, "Seed buffer overrun\n"); return; } cryptodev_start_session(&session, &cryptofd); for (i = 0; i < 10000; i++) { if (cryptodev_session_op(session, cryptofd, op) <= 0) { fprintf(stderr, "Error getting PRNG value\n"); return; } } cryptodev_end_session(session, cryptofd); OutputValue("R", ret, 16, out, 0); OPENSSL_free(key); key = NULL; OPENSSL_free(dt); dt = NULL; OPENSSL_free(v); v = NULL; } } } #ifdef FIPS_ALGVS int fips_rngvs_main(int argc, char **argv) #else int main(int argc, char **argv) #endif { FILE *in, *out; if (argc == 4) { in = fopen(argv[2], "r"); if (!in) { fprintf(stderr, "Error opening input file\n"); exit(1); } out = fopen(argv[3], "w"); if (!out) { fprintf(stderr, "Error opening output file\n"); exit(1); } } else if (argc == 2) { in = stdin; out = stdout; } else { fprintf(stderr,"%s [mct|vst]\n",argv[0]); exit(1); } if(!strcmp(argv[1],"mct")) mct(in, out); else if(!strcmp(argv[1],"vst")) vst(in, out); else { fprintf(stderr,"Don't know how to %s.\n",argv[1]); exit(1); } if (argc == 4) { fclose(in); fclose(out); } return 0; }