예제 #1
0
파일: instructions.c 프로젝트: cfdrake/cant
/*
 * Executes a given instruction, or errors out
 * ins - instruction to run
 */
void
execute (unsigned short int ins)
{
    /* seperate instruction into parts */
    short int a0 = (ins >> 12) % 16;
    short int a1 = (ins >> 8) % 16;
    short int a2 = (ins >> 4) % 16;
    short int a3 = (ins >> 0) % 16;

    /* Run associated instruction */
    switch(a0) {
    case 0x0:
        _add (a1, a2, a3);
        break;
    case 0x1:
        _sub (a1, a2, a3);
        break;
    case 0x2:
        _mul (a1, a2, a3);
        break;
    case 0x3:
        _div (a1, a2, a3);
        break;
    case 0x6:
        _beq (a1, a2, a3);
        break;
    case 0x7:
        _bgt (a1, a2, a3);
        break;
    case 0x8:
        _ld (a1, a2, a3);
        break;
    case 0x9:
        _st (a1, a2, a3);
        break;
    case 0xa:
        _lc (a1, a3);
        break;
    case 0xb:
        _jmp (a1, a3);
        break;
    case 0xc:
        _inc (a1, a3);
        break;
    case 0xf:
        _sys (a1, a3);
        break;
    default:
        printf ("Error: invalid opcode %#x.\n", a0);
        sys_dump (0x0);
        sys_halt (0x0);
    }
}
예제 #2
0
파일: keymgmt.c 프로젝트: TLINDEN/pcp
void pcp_keygen(char *passwd) {
  pcp_key_t *k = pcpkey_new ();
  pcp_key_t *key = NULL;

  char *owner =  pcp_getstdin("Enter the name of the key owner");
  if(owner != NULL)
    memcpy(k->owner, owner, strlen(owner) + 1);

  char *mail = pcp_getstdin("Enter the email address of the key owner");
  if(mail != NULL)
    memcpy(k->mail, _lc(mail), strlen(mail) + 1);

  if(debug)
      pcp_dumpkey(k);

  char *passphrase;
  if(passwd == NULL) {
    pcp_readpass(ptx, &passphrase,
                 "Enter passphrase for key encryption",
                 "Enter the passphrase again", 1, NULL);
  }
  else {
    passphrase = passwd;
  }

  if(strnlen(passphrase, 1024) > 0) {
    double ent = pcp_getentropy(passphrase);
    if(ent < 3.32) {
      fprintf(stderr, "WARNING: you are using a weak passphrase (entropy: %lf)!\n", ent);
      char *yes = pcp_getstdin("Are you sure to use it [yes|NO]?");
      if(strncmp(yes, "yes", 1024) != 0) {
        goto errkg1;
      }
    }
    key = pcpkey_encrypt(ptx, k, passphrase);
  }
  else {
    /* No unencrypted secret key allowed anymore [19.08.2015, tom] */
    memset(k, 0, sizeof(pcp_key_t));
    free(k);
    goto errkg1;
  }

  if(key != NULL) {
    fprintf(stderr, "Generated new secret key:\n");
    if(pcp_storekey(key) == 0) {
      pcpkey_printshortinfo(key);
      memset(key, 0, sizeof(pcp_key_t));
      free(key);
    }
  }

  if(passwd == NULL) {
    /* if passwd is set, it'll be free'd in main() */
    sfree(passphrase);
  }
  
 errkg1:
  free(mail);
  free(owner);
}