method_info* read_method(classfile* c, FILE* stream){ method_info* m = malloc(sizeof(method_info)); memcheck(m); m->access_flags = read16(stream); m->name_index = read16(stream); m->descriptor_index = read16(stream); m->attributes_count = read16(stream); m->code = NULL; //assert(m->attributes_count == 1); if(m->attributes_count > 0){ m->attributes = malloc(sizeof(void*) * m->attributes_count); memcheck(m->attributes); for(int i = 0; i < m->attributes_count; i++){ m->attributes[i] = read_attribute(stream); // look for the code attribute, and once it is found, build // a code object too. char* name = get_constant_name(c, m->attributes[i]->name_index); if(strcmp(name, "Code") == 0){ //found the code attribute. m->code = malloc(sizeof(code_attribute)); m->code->attribute_name_index = m->attributes[i]->name_index; m->code->attribute_length = m->attributes[i]->attribute_length; unsigned short s = 0; unsigned char* c = (unsigned char*) &s; c[1] = m->attributes[i]->info[0]; c[0] = m->attributes[i]->info[1]; m->code->max_stack = s; c[1] = m->attributes[i]->info[2]; c[0] = m->attributes[i]->info[3]; m->code->max_locals = s; unsigned int l = 0; c = (unsigned char*) &l; c[3] = m->attributes[i]->info[4]; c[2] = m->attributes[i]->info[5]; c[1] = m->attributes[i]->info[6]; c[0] = m->attributes[i]->info[7]; m->code->code_length = l; m->code->code = malloc(l); memcheck(m->code->code); memcpy((char*) m->code->code, (char*) m->attributes[i]->info + 8, l); } } } return m; }
static void make_hmac(const struct hop *hops, size_t num_hops, const struct hop *padding, const struct hmackey *hmackey, struct sha256 *hmac) { HMAC_CTX ctx; size_t len, padlen; /* Calculate HMAC of padding then onion up to and including pubkey. */ HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, memcheck(hmackey->k.u.u8, sizeof(hmackey->k)), sizeof(hmackey->k), EVP_sha256(), NULL); padlen = (MAX_HOPS - num_hops) * sizeof(struct hop); HMAC_Update(&ctx, memcheck((unsigned char *)padding, padlen), padlen); len = num_hops*sizeof(struct hop) - sizeof(hops->hmac); HMAC_Update(&ctx, memcheck((unsigned char *)hops, len), len); HMAC_Final(&ctx, hmac->u.u8, NULL); }
void privkey_sign(struct peer *peer, const void *src, size_t len, struct signature *sig) { struct sha256_double h; sha256_double(&h, memcheck(src, len), len); sign_hash(peer->dstate->secpctx, &peer->dstate->secret->privkey, &h, sig); }
void push_cond( int ok, STREAM *str) { last_cond++; assert(last_cond < MAX_CONDS); conds[last_cond].ok = ok; conds[last_cond].file = memcheck(strdup(str->name)); conds[last_cond].line = str->line; }
char* entreeDynamique(FILE* input) { // 32 bytes par défaut. int defaut = 32; char* mot = malloc(sizeof(char) * defaut); memcheck(mot); int taille = 0; char c; while(1) { c = fgetc(input); if(c == EOF || c == '\n') { break; } mot[taille] = c; taille++; // "realloc" si la ligne est plus grande que l'espace alloué. if(taille > defaut) { defaut += 32; mot = realloc(mot, sizeof(char) * defaut); memcheck(mot); } } if(taille > defaut) { taille++; mot = realloc(mot, sizeof(char) * taille); memcheck(mot); } // Pour terminer la string. mot[taille] = '\0'; return mot; }
/**********************Function To Renew A Member****************************/ void renewmem() { FILE *tt; int no,ch; clrscr(); tt=fopen("temp1.dat","w"); printf("\n\t Enter Membership Id::"); scanf("%d",&no); ch=memcheck(no); if(ch==FALSE) { printf("\n\t No Such Member....."); getch(); return; } rewind(fm); while( fread(&M,sizeof(M),1,fm)==1 ) { if(M.mid==no) { M.me.mon=(M.me.mon+6); if(M.me.mon>12 && M.me.mon!=12) { M.me.year+=1; M.me.mon=(M.me.mon-12); } if(M.me.day==31) { if(M.me.mon==4 || M.me.mon==6 || M.me.mon==9 || M.me.mon==11) { M.me.day=1; M.me.mon+=1; } if(M.me.mon==2) { if( (M.me.year%4)==0) { M.me.day=31-29; M.me.mon+=1; } else { M.me.day=31-28; M.me.mon+=1; } } } fwrite(&M,sizeof(M),1,tt); } else fwrite(&M,sizeof(M),1,tt); } fclose(tt); fclose(fm); remove("member.dat"); rename("temp1.dat","member.dat"); fm=fopen("member.dat","a+"); printf("\n\t Member Renewed.."); getch(); transac1(no,'E'); }
static void dump_contents(const void *data, size_t n) { size_t i; const unsigned char *p = memcheck(data, n); for (i = 0; i < n; i++) { printf("%02x", p[i]); if (i % 16 == 15) printf("\n"); } }
static void sha_with_seed(const unsigned char secret[32], unsigned char seed, struct sha256 *res) { struct sha256_ctx ctx; sha256_init(&ctx); sha256_update(&ctx, memcheck(secret, 32), 32); sha256_u8(&ctx, seed); sha256_done(&ctx, res); }
SECTION *new_section( void) { SECTION *sect = memcheck(malloc(sizeof(SECTION))); sect->flags = 0; sect->size = 0; sect->pc = 0; sect->type = 0; sect->sector = 0; sect->label = NULL; return sect; }
bool_t zcl_comm_sas_is_valid( zcl_comm_state_t FAR *comm) { if (comm->sas.startup_control != ZCL_COMM_STARTUP_FROM_SCRATCH) { // Extended PAN ID is required for all but "from scratch" if (memcheck( &comm->sas.extended_panid, 0xFF, 8) == 0 || memcheck( &comm->sas.extended_panid, 0x00, 8) == 0) { return FALSE; } } switch (comm->sas.startup_control) { case ZCL_COMM_STARTUP_JOINED: // must have short address, panid, trust center, network key, // key seq num and key type if (comm->sas.short_address == WPAN_NET_ADDR_COORDINATOR) { // must support coordinator mode } else { // must support non-coordinator mode } break; case ZCL_COMM_STARTUP_COORDINATOR: break; case ZCL_COMM_STARTUP_REJOIN: break; case ZCL_COMM_STARTUP_FROM_SCRATCH: break; } return TRUE; }
/* This is a constant time verify */ int ccrsa_emsa_pkcs1v15_verify(size_t emlen, uint8_t *em, size_t dgstlen, const uint8_t *dgst, const uint8_t *oid) { size_t tlen; size_t oidlen=oid[1]; uint8_t r=0; #define bytecheck(v) r|=(*em++)^(v) #define memcheck(s, len) r|=cc_cmp_safe((len),em, (s)); em+=(len) assert(oid[0]==0x06); tlen=2+2+oidlen+2+2+dgstlen+2; if(emlen<tlen+11) return -1; size_t pslen = emlen-3-tlen; bytecheck(0x00); bytecheck(0x01); while(pslen--) bytecheck(0xff); bytecheck(0x00); bytecheck(0x30); bytecheck(tlen-2); bytecheck(0x30); bytecheck(oidlen+4); memcheck(oid, oidlen+2); bytecheck(0x05); bytecheck(0x00); bytecheck(0x04); bytecheck(dgstlen); memcheck(dgst, dgstlen); return r; }
void t_memcheck( void) { char error[80]; int i, retval; bool_t result; for (i = 0; i < _TABLE_ENTRIES( test); ++i) { sprintf( error, "entry %u, testing for 0x%02X, expected %d", i, test[i].test_char, test[i].expected); retval = memcheck( test[i].values, test[i].test_char, test[i].length); switch (test[i].expected) { case -1: result = (retval < 0); break; case 0: result = (retval == 0); break; case +1: result = (retval > 0); break; default: result = FALSE; break; } test_bool( result, error); } test_bool( memcheck( "\xFF\xFF\xFF", 0xFF, 3) == 0, "0xFF check failed"); }
/********************Function To Issue Duplicate Id Card*********************/ void memdupid() { int no,ch; clrscr(); printf("\n\t Enter Membership Id::"); scanf("%d",&no); ch=memcheck(no); if(ch==FALSE) { printf("\n\t No Such Member....."); getch(); return; } printf("\n\t Duplicate ID Issued...."); getch(); transac1(no,'D'); }
static bool aes_decrypt(void *dst, const void *src, size_t len, const struct enckey *enckey, const struct iv *iv) { EVP_CIPHER_CTX evpctx; int outlen; /* Counter mode allows parallelism in future. */ if (EVP_DecryptInit(&evpctx, EVP_aes_128_ctr(), memcheck(enckey->k.u.u8, sizeof(enckey->k)), memcheck(iv->iv, sizeof(iv->iv))) != 1) return false; /* No padding, we're a multiple of 128 bits. */ if (EVP_CIPHER_CTX_set_padding(&evpctx, 0) != 1) return false; EVP_DecryptUpdate(&evpctx, dst, &outlen, memcheck(src, len), len); assert(outlen == len); /* Shouldn't happen (no padding) */ if (EVP_DecryptFinal(&evpctx, dst, &outlen) != 1) return false; assert(outlen == 0); return true; }
/** Print UNIX-like process status table Thsi is expensive but should be run occasionally **/ void Processes::status() { Serial.println(); Serial.println(F("pid \t enable \t interval \t last run \t callback \t label")); Serial.println(F("--- \t ------ \t -------- \t -------- \t -------- \t -----")); Serial.flush(); delay(10); for (size_t i=0; i<num_tasks; i++) { Serial.print(tasks[i]->id); Serial.print(F("\t ")); delay(10); tasks[i]->enabled ? Serial.print(F("true ")) : Serial.print(F("false")); Serial.print(F("\t\t ")); delay(10); Serial.print(tasks[i]->interval); Serial.print(F("\t\t ")); delay(10); Serial.print(tasks[i]->last_run); Serial.print(F("\t\t ")); delay(10); /* Apparently this cast is fine 0_o */ Serial.print((uint16_t) tasks[i]->callback, HEX); Serial.print(F("\t\t ")); delay(10); Serial.print(tasks[i]->label); Serial.println(); Serial.flush(); delay(10); } Serial.println(F("--- \t ------ \t -------- \t -------- \t -------- \t -----")); delay(10); Serial.print(F("mem: ")); Serial.print(memcheck()); Serial.print(F(" free of ")); Serial.println(RAMEND - RAMSTART +1, DEC); Serial.flush(); delay(10); }
/* Sets *cursor to NULL and returns NULL when a pull fails. */ const u8 *pull(const u8 **cursor, size_t *max, void *copy, size_t n) { const u8 *p = *cursor; if (*max < n) { *cursor = NULL; *max = 0; /* Just make sure we don't leak uninitialized mem! */ if (copy) memset(copy, 0, n); return NULL; } *cursor += n; *max -= n; if (copy) memcpy(copy, p, n); return memcheck(p, n); }
TCL_GLOBAL create_tcl_global() { TCL_GLOBAL tmp; int i; tmp = (TCL_GLOBAL) malloc( sizeof( struct tcl_glob_struct ) ); memcheck( tmp, "TCL Global Structure" ); tmp->name = (char *) NULL; tmp->type = -1; tmp->char_value = (char *) NULL; tmp->int_value = -1; return( tmp ); }
char *getstring( char *cp, char **endp) { int len; int start; char *str; if (!brackrange(cp, &start, &len, endp)) { start = 0; len = strcspn(cp, " \t\n,;"); if (endp) *endp = cp + len; } str = memcheck(malloc(len + 1)); memcpy(str, cp + start, len); str[len] = 0; return str; }
static void append_env( char *envname, char *value) { char *env = getenv(envname); char *temp; if (env == NULL) env = ""; temp = memcheck(malloc(strlen(envname) + 1 + strlen(env) + 1 + strlen(value) + 1)); strcpy(temp, envname); strcat(temp, "="); strcat(temp, env); strcat(temp, PATHSEP); strcat(temp, value); putenv(temp); }
void retbook() { int i,j,k,id; int f1,f2,f3; f3=FALSE; clrscr(); gotoxy(5,1); cprintf("Enter Book id::"); gotoxy(9,2); cprintf("/");gotoxy(13,2); cprintf("/"); gotoxy(5,2); scanf("%d",&i); gotoxy(10,2); scanf("%d",&j); gotoxy(14,2);scanf("%d",&k); f1=chkbook(i,j,k); if(f1==FALSE) { printf("\n\t No Such Book....."); getch(); return; } printf("\n\t Enter Membership id::"); scanf("%d",&id); f2=memcheck(id); if(f2==FALSE) { printf("\n\t No Such Member....."); getch(); return; } rewind(ft); while(fread(&T,sizeof(T),1,ft)==1) { if(T.mid==id && T.b.bno==i && T.b.gno==j && T.b.no==k && T.reason=='I') { f3=TRUE; break;} } if(f3==TRUE) { transac2(id,i,j,k,'R'); } else printf("\n\t No Such Transaction In The Records......"); }
static void add_sha(const void *data, size_t len, void *shactx_) { struct sha256_ctx *ctx = shactx_; sha256_update(ctx, memcheck(data, len), len); }
/** * Opération d'addition. */ num* addition(num* a, num* b, int ancien_a_positif, int ancien_b_positif) { if(a->positif == 0 && b->positif == 1) { a->positif = 1; return soustraction(b, a, ancien_b_positif, ancien_a_positif); // Vu que a et b sont inversés, leur "ancien_a_positif" et "ancien_b_positif" aussi. } if(a->positif == 1 && b->positif == 0) { b->positif = 1; return soustraction(a, b, ancien_a_positif, ancien_b_positif); } if(a->positif == 0 && b->positif == 0) { b->positif = 1; return soustraction(a, b, ancien_a_positif, ancien_b_positif); } setupNombres(a, b); cell* cA = a->nombre; cell* cB = b->nombre; if(!cA || !cB) { return NULL; } cell* result = malloc(sizeof(cell)); memcheck(result); num* r = malloc(sizeof(num)); memcheck(r); r->longueur = 0; int fini = 0; int intermediaire = 0; int carry = 0; cell* newUnit = NULL; r->nombre = result; while(!fini) { fini = cA->suivant == NULL && cB->suivant == NULL; intermediaire = cA->chiffre + cB->chiffre + carry; if(intermediaire > 9) { carry = 1; intermediaire -= 10; } else { carry = 0; } result->chiffre = intermediaire; if(!fini) { // Ajustement des pointeurs pour le prochain round si pertinent. newUnit = malloc(sizeof(cell)); memcheck(newUnit); newUnit->suivant = NULL; newUnit->precedent = result; result->suivant = newUnit; result = newUnit; } cA = cA->suivant; cB = cB->suivant; r->longueur++; } if(newUnit == NULL) { // Cas particulier où on n'a pas de "carry" et un seul digit dans chaque opérande (ex : 2+2). result->suivant = NULL; r->dernier = result; } else { newUnit->suivant = NULL; r->dernier = newUnit; } if(carry) { cell* carryCell = malloc(sizeof(cell)); memcheck(carryCell); carryCell->chiffre = carry; carryCell->precedent = result; result->suivant = carryCell; carryCell->suivant = NULL; r->dernier = carryCell; r->longueur++; } r->positif = 1; a->positif = ancien_a_positif; b->positif = ancien_b_positif; return r; }
/** * Opération de soustraction. */ num* soustraction(num* a, num* b, int ancien_a_positif, int ancien_b_positif) { if(a->positif == 0 && b->positif == 1) { a->positif = 1; num* res = addition(a, b, ancien_a_positif, ancien_b_positif); res->positif = 0; return res; } cell* result = malloc(sizeof(cell)); memcheck(result); cell* newUnit = NULL; cell* cA = NULL; cell* cB = NULL; int fini = 0; int retenue = 0; int intermediaire = 0; num* r = malloc(sizeof(num)); memcheck(r); r->longueur = 0; if(numComparator(a,b) == -1) { num* temp = a; a = b; b = temp; r->positif = 0; } else { r->positif = 1; } setupNombres(a, b); cA = a->nombre; cB = b->nombre; r->nombre = result; do { fini = cA->suivant == NULL && cB->suivant == NULL; intermediaire = cA->chiffre - cB->chiffre; if(intermediaire < 0) { cA->chiffre += 10; if(cA->suivant != NULL) { cA->suivant->chiffre--; } intermediaire = cA->chiffre - cB->chiffre; } result->chiffre = intermediaire; if(!fini) { // Ajustement des pointeurs pour le prochain round si pertinent. newUnit = malloc(sizeof(cell)); memcheck(newUnit); newUnit->precedent = result; result->suivant = newUnit; result = newUnit; } r->longueur++; cA = cA->suivant; cB = cB->suivant; } while(!fini); if(newUnit == NULL) { result->suivant = NULL; r->dernier = result; } else { newUnit->suivant = NULL; r->dernier = newUnit; } if(numComparator(b,a) == -1) { num* temp_reverse = a; a = b; b = temp_reverse; } a->positif = ancien_a_positif; b->positif = ancien_b_positif; return r; }
cp_info* read_constant(int index, FILE* stream){ unsigned char c = read8(stream); unsigned int burn_length = 0; switch(c){ case 1: burn_length = read16(stream); break; case 3: burn_length = 4; break; case 4: burn_length = 4; break; case 5: burn_length = 8; break; case 6: burn_length = 8; break; case 7: burn_length = 2; break; case 8: burn_length = 2; break; case 9: burn_length = 4; break; case 10: burn_length = 4; break; case 11: burn_length = 4; break; case 12: burn_length = 4; break; case 15: burn_length = 3; break; case 16: burn_length = 2; break; case 18: burn_length = 4; break; default: burn_length = 0; } // fprintf(stderr, "%d\n", c); cp_info* cp = malloc(sizeof(cp_info)); memcheck(cp); cp->tag = c; cp->cp_length = burn_length; cp->info = malloc(burn_length + 1); cp->info[burn_length] = 0; // assert(burn_length > 0); for(int i = 0; i < burn_length; i++){ unsigned char next = read8(stream); cp->info[i] = next; } return cp; }
/** * Opération de multiplication. */ num* multiplication(num* a, num* b) { cell* cA = a->nombre; cell* cB = b->nombre; cell* result = NULL; num* listeToAdd = malloc(b->longueur * sizeof(num)); memcheck(listeToAdd); num* r = malloc(sizeof(num)); memcheck(r); r->longueur = 0; r->positif = a->positif == b->positif; int finiCB = 0; int finiCA = 0; int intermediaire = 0; int carry = 0; int chiffreCourant = 0; int decalageUnit = 0; cell* newUnit = NULL; do { chiffreCourant = cB->chiffre; cA = a->nombre; result = malloc(sizeof(cell)); memcheck(result); result->suivant = NULL; result->precedent = NULL; r->nombre = result; r->longueur = 0; carry = 0; do { // Multiplication en tant que telle. finiCA = cA->suivant == NULL; intermediaire = chiffreCourant * cA->chiffre + carry; carry = 0; while(intermediaire > 9) { carry++; intermediaire -= 10; } result->chiffre = intermediaire; if(!finiCA) { // Ajustement des pointeurs pour le prochain round si pertinent. newUnit = malloc(sizeof(cell)); memcheck(newUnit); newUnit->precedent = result; result->suivant = newUnit; result = newUnit; } cA = cA->suivant; r->longueur++; } while(!finiCA); if(newUnit == NULL) { // Cas particulier si un seul digit dans chaque opérande (ex: 2*2). result->suivant = NULL; r->dernier = result; } else { newUnit->suivant = NULL; r->dernier = newUnit; } // Ajuster le carry s'il le faut. if(carry) { cell* carryCell = malloc(sizeof(cell)); memcheck(carryCell); carryCell->chiffre = carry; carryCell->precedent = result; result->suivant = carryCell; carryCell->suivant = NULL; r->dernier = carryCell; r->longueur++; } // Ajuster les zéros. cell* newZero = NULL; cell* currentZero = NULL; cell* premierZero = NULL; int i = 0; if(decalageUnit > 0) { currentZero = malloc(sizeof(cell)); memcheck(currentZero); currentZero->chiffre = 0; currentZero->precedent = NULL; premierZero = currentZero; for(i = 1; i < decalageUnit; i++) { newZero = malloc(sizeof(cell)); memcheck(newZero); newZero->precedent = currentZero; newZero->chiffre = 0; currentZero->suivant = newZero; currentZero = newZero; } r->nombre->precedent = currentZero; currentZero->suivant = r->nombre; r->nombre = premierZero; r->longueur += i; } listeToAdd[decalageUnit] = *r; cB = cB->suivant; finiCB = cB == NULL; decalageUnit++; } while(!finiCB); int j; num* somme = malloc(sizeof(num)); memcheck(somme); strToBigNum("0", somme); for(j = 0; j < b->longueur; j++) { somme = addition(somme, &listeToAdd[j], somme->positif, (&listeToAdd[j])->positif); } superFree(listeToAdd); return somme; }
int main( int argc, char *argv[]) { char *fnames[32]; int nr_files = 0; FILE *obj = NULL; TEXT_RLD tr; char *objname = NULL; char *lstname = NULL; int arg; int i; STACK stack; int errcount; if (argc <= 1) { print_help(); exit(EXIT_FAILURE); } for (arg = 1; arg < argc; arg++) if (*argv[arg] == '-') { char *cp; cp = argv[arg] + 1; if (!stricmp(cp, "h")) { print_help(); } else if (!stricmp(cp, "v")) { print_version(stderr); } else if (!stricmp(cp, "e")) { /* Followed by options to enable */ /* Since /SHOW and /ENABL option names don't overlap, I consolidate. */ if(arg >= argc-1 || !isalpha((unsigned char)*argv[arg+1])) { usage("-e must be followed by an option to enable\n"); } upcase(argv[++arg]); enable_tf(argv[arg], 1); } else if (!stricmp(cp, "d")) { /* Followed by an option to disable */ if(arg >= argc-1 || !isalpha((unsigned char)*argv[arg+1])) { usage("-d must be followed by an option to disable\n"); } upcase(argv[++arg]); enable_tf(argv[arg], 0); } else if (!stricmp(cp, "m")) { /* Macro library */ /* This option gives the name of an RT-11 compatible macro library from which .MCALLed macros can be found. */ if(arg >= argc-1 || *argv[arg+1] == '-') { usage("-m must be followed by a macro library file name\n"); } arg++; int allow_olb = strcmp(argv[argc-1], "-x") == 0; mlbs[nr_mlbs] = mlb_open(argv[arg], allow_olb); if (mlbs[nr_mlbs] == NULL) { fprintf(stderr, "Unable to register macro library %s\n", argv[arg]); exit(EXIT_FAILURE); } nr_mlbs++; } else if (!stricmp(cp, "p")) { /* P for search path */ /* The -p option gives the name of a directory in which .MCALLed macros may be found. */ { if(arg >= argc-1 || *argv[arg+1] == '-') { usage("-p must be followed by a macro search directory\n"); } append_env("MCALL", argv[arg+1]); arg++; } } else if (!stricmp(cp, "I")) { /* I for include path */ /* The -I option gives the name of a directory in which .included files may be found. */ { if(arg >= argc-1 || *argv[arg+1] == '-') { usage("-I must be followed by a include file search directory\n"); } append_env("INCLUDE", argv[arg+1]); arg++; } } else if (!stricmp(cp, "o")) { /* The -o option gives the object file name (.OBJ) */ if(arg >= argc-1 || *argv[arg+1] == '-') { usage("-o must be followed by the object file name\n"); } ++arg; objname = argv[arg]; } else if (!stricmp(cp, "l")) { /* The option -l gives the listing file name (.LST) */ /* -l - enables listing to stdout. */ if(arg >= argc-1 || (argv[arg+1][0] == '-' && argv[arg+1][1] != '\0')) { usage("-l must be followed by the listing file name (- for standard output)\n"); } lstname = argv[++arg]; if (strcmp(lstname, "-") == 0) lstfile = stdout; else lstfile = fopen(lstname, "w"); } else if (!stricmp(cp, "x")) { /* The -x option invokes macro11 to expand the contents of the registered macro libraries (see -m) into individual .MAC files in the current directory. No assembly of input is done. This must be the last command line option. */ int m; if(arg != argc-1) { usage("-x must be the last option\n"); } for (m = 0; m < nr_mlbs; m++) mlb_extract(mlbs[m]); return EXIT_SUCCESS; } else if (!stricmp(cp, "ysl")) { /* set symbol_len */ if (arg >= argc-1) { usage("-s must be followed by a number\n"); } else { char *s = argv[++arg]; char *endp; int sl = strtol(s, &endp, 10); if (*endp || sl < SYMMAX_DEFAULT || sl > SYMMAX_MAX) { usage("-s must be followed by a number\n"); } symbol_len = sl; } } else if (!stricmp(cp, "yus")) { /* allow underscores */ symbol_allow_underscores = 1; } else if (!stricmp(cp, "yl1")) { /* list the first pass, in addition to the second */ list_pass_0++; } else if (!stricmp(cp, "yd")) { enabl_debug++; } else { fprintf(stderr, "Unknown option %s\n", argv[arg]); print_help(); exit(EXIT_FAILURE); } } else { fnames[nr_files++] = argv[arg]; } if (objname) { obj = fopen(objname, "wb"); if (obj == NULL) return EXIT_FAILURE; } add_symbols(&blank_section); text_init(&tr, NULL, 0); module_name = memcheck(strdup(".MAIN.")); xfer_address = new_ex_lit(1); /* The undefined transfer address */ stack_init(&stack); /* Push the files onto the input stream in reverse order */ for (i = nr_files - 1; i >= 0; --i) { STREAM *str = new_file_stream(fnames[i]); if (str == NULL) { report(NULL, "Unable to open file %s\n", fnames[i]); exit(EXIT_FAILURE); } stack_push(&stack, str); } DOT = 0; current_pc->section = &blank_section; last_dot_section = NULL; pass = 0; stmtno = 0; lsb = 0; next_lsb = 1; lsb_used = 0; last_macro_lsb = -1; last_locsym = 32767; last_cond = -1; sect_sp = -1; suppressed = 0; assemble_stack(&stack, &tr); if (list_pass_0 && lstfile) { list_symbol_table(); } #if 0 if (enabl_debug > 1) dump_all_macros(); #endif assert(stack.top == NULL); migrate_implicit(); /* Migrate the implicit globals */ write_globals(obj); /* Write the global symbol dictionary */ #if 0 sym_hist(&symbol_st, "symbol_st"); /* Draw a symbol table histogram */ #endif text_init(&tr, obj, 0); stack_init(&stack); /* Superfluous... */ /* Re-push the files onto the input stream in reverse order */ for (i = nr_files - 1; i >= 0; --i) { STREAM *str = new_file_stream(fnames[i]); if (str == NULL) { report(NULL, "Unable to open file %s\n", fnames[i]); exit(EXIT_FAILURE); } stack_push(&stack, str); } DOT = 0; current_pc->section = &blank_section; last_dot_section = NULL; pass = 1; stmtno = 0; lsb = 0; next_lsb = 1; lsb_used = 0; last_macro_lsb = -1; last_locsym = 32767; pop_cond(-1); sect_sp = -1; suppressed = 0; errcount = assemble_stack(&stack, &tr); text_flush(&tr); while (last_cond >= 0) { report(NULL, "%s:%d: Unterminated conditional\n", conds[last_cond].file, conds[last_cond].line); pop_cond(last_cond - 1); errcount++; } for (i = 0; i < nr_mlbs; i++) mlb_close(mlbs[i]); write_endmod(obj); if (obj != NULL) fclose(obj); if (errcount > 0) fprintf(stderr, "%d Errors\n", errcount); if (lstfile) { list_symbol_table(); } if (lstfile && strcmp(lstname, "-") != 0) fclose(lstfile); return errcount > 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
/* * This is the ioctl implementation. */ static long kern_unlocked_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { /* for results from functions */ int res; PR_DEBUG("start with cmd %d", cmd); switch (cmd) { /* * Asking the kernel to mmap into user space. * Only argument is size. */ case IOCTL_DEMO_MAP: PR_DEBUG("trying to mmap"); size = arg; kptr = alloc_mem(size); if (kptr == NULL) { PR_ERROR("ERROR: could not allocate memory"); return -EFAULT; } PR_DEBUG("After alloc_mem with kptr=%p", kptr); uptr = map_to_user(filp, kptr, size); if (IS_ERR_VALUE(uptr)) { PR_ERROR("ERROR: quiting on process of mmaping"); return -EFAULT; } PR_DEBUG("After map_to_user"); PR_DEBUG("Successful exit"); return uptr; /* * Asking the kernel to munmap user space. * No arguments are required. */ case IOCTL_DEMO_UNMAP: PR_DEBUG("trying to munmap"); res = do_munmap(current->mm, uptr, size); if (res) return res; PR_DEBUG("After unmap"); free_mem(kptr, size); PR_DEBUG("Successful exit"); /* so we won't accidentaly use these pointers */ kptr = NULL; size = -1; uptr = -1; return 0; /* * Asking the kernel to write to the buffer. * One argument which is the value to write. */ case IOCTL_DEMO_WRITE: if (kptr == NULL) { PR_ERROR("ERROR: kptr is NULL?!?"); return -EFAULT; } memset(kptr, arg, size); return 0; /* * Asking the kernel to check that the buffer is a certain value. * One argument which is the value to check. */ case IOCTL_DEMO_READ: if (kptr == NULL) { PR_ERROR("ERROR: kptr is NULL?!?"); return -EFAULT; } return memcheck(kptr, arg, size); /* * Asking the kernel to copy the in kernel buffer to user space. * One argument which is the pointer to the user space buffer. */ case IOCTL_DEMO_COPY: if (kptr == NULL) { PR_ERROR("ERROR: kptr is NULL?!?"); return -EFAULT; } return copy_to_user((void *)arg, kptr, size); } return -EINVAL; }
int main(void){ memory = bcalloc(sizeof(union memory)); memcheck(); execute(); return 0; }
static bool create_onion(const secp256k1_pubkey pubkey[], char *const msg[], size_t num, struct onion *onion) { int i; struct seckey seckeys[MAX_HOPS]; struct onion_pubkey pubkeys[MAX_HOPS]; struct enckey enckeys[MAX_HOPS]; struct hmackey hmackeys[MAX_HOPS]; struct iv ivs[MAX_HOPS]; struct iv pad_ivs[MAX_HOPS]; HMAC_CTX padding_hmac[MAX_HOPS]; struct hop padding[MAX_HOPS]; size_t junk_hops; secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); bool ok = false; if (num > MAX_HOPS) goto fail; /* FIXME: I think it would be safe to reuse a single disposable key * here? */ /* First generate all the keys. */ for (i = 0; i < num; i++) { unsigned char secret[32]; gen_keys(ctx, &seckeys[i], &pubkeys[i]); /* Make shared secret. */ if (!secp256k1_ecdh(ctx, secret, &pubkey[i], seckeys[i].u.u8)) goto fail; hmackeys[i] = hmackey_from_secret(memcheck(secret, 32)); enckeys[i] = enckey_from_secret(secret); ivs_from_secret(secret, &ivs[i], &pad_ivs[i]); } /* * Building the onion is a little tricky. * * First, there is the padding. That's generated by previous nodes, * and "decrypted" by the others. So we have to generate that * forwards. */ for (i = 0; i < num; i++) { if (i > 0) { /* Previous node decrypts padding before passing on. */ aes_decrypt(padding, padding, sizeof(struct hop)*(i-1), &enckeys[i-1], &ivs[i-1]); memmove(padding + 1, padding, sizeof(struct hop)*(i-1)); } /* And generates more padding for next node. */ add_padding(&padding[0], &enckeys[i-1], &pad_ivs[i-1]); HMAC_CTX_init(&padding_hmac[i]); HMAC_Init_ex(&padding_hmac[i], hmackeys[i].k.u.u8, sizeof(hmackeys[i].k), EVP_sha256(), NULL); HMAC_Update(&padding_hmac[i], memcheck((unsigned char *)padding, i * sizeof(struct hop)), i * sizeof(struct hop)); } /* * Now the normal onion is generated backwards. */ /* Unused hops filled with random, so even recipient can't tell * how many were used. */ junk_hops = MAX_HOPS - num; random_bytes(onion->hop, junk_hops * sizeof(struct hop)); for (i = num - 1; i >= 0; i--) { size_t other_hops, len; struct hop *myhop; other_hops = num - i - 1 + junk_hops; /* Our entry is at tail of onion. */ myhop = onion->hop + other_hops; /* Now populate our hop. */ myhop->pubkey = pubkeys[i]; /* Set message. */ assert(strlen(msg[i]) < MESSAGE_SIZE); memset(myhop->msg, 0, MESSAGE_SIZE); strcpy((char *)myhop->msg, msg[i]); /* Encrypt whole thing, including our message, but we * aware it will be offset by the prepended padding. */ if (!aes_encrypt_offset(i * sizeof(struct hop), onion, onion, other_hops * sizeof(struct hop) + sizeof(myhop->msg), &enckeys[i], &ivs[i])) goto fail; /* HMAC covers entire thing except hmac itself. */ len = (other_hops + 1)*sizeof(struct hop) - sizeof(myhop->hmac); HMAC_Update(&padding_hmac[i], memcheck((unsigned char *)onion, len), len); HMAC_Final(&padding_hmac[i], myhop->hmac.u.u8, NULL); } ok = true; fail: secp256k1_context_destroy(ctx); return ok; }