int
main(void)
{
  static uint8_t state[16];
  static uint8_t prev_state[16];

  // set for 16 MHz clock
  CPU_PRESCALE(0);

  init_keyboard_interface();

  // Initialize the USB, and then wait for the host to set configuration.
  // If the Teensy is powered without a PC connected to the USB port,
  // this will wait forever.
  usb_init();
  while (!usb_configured()) /* wait */ ;

  // Wait for the PC's operating system to load drivers
  // and do whatever it does to actually be ready for input
  _delay_ms(3000);

  memset(prev_state, 0, sizeof prev_state);
  while (1) {
    poll_keyboard(state);
    if (memcmp(state, prev_state, sizeof state)) {
      send_keys(state);
      memcpy(prev_state, state, sizeof state);
    }
    _delay_ms(10);
  }
}
Exemple #2
0
  void synchronize_effort_keys(effort_data& effort_log, MPI_Comm comm) {
    int rank, size;
    PMPI_Comm_rank(comm, &rank);
    PMPI_Comm_size(comm, &size);

    relatives rels = get_radix_relatives(rank, size);
    if (rels.left >= 0)  receive_keys(effort_log, rels.left, comm);
    if (rels.right >= 0) receive_keys(effort_log, rels.right, comm);
  
    if (rels.parent >= 0) {
      send_keys(effort_log, rels.parent, comm);
      receive_keys(effort_log, rels.parent, comm);
    }

    // TODO: be more efficient and only propagate the difference 
    // back up the tree.
    if (rels.left >= 0)  send_keys(effort_log, rels.left, comm);
    if (rels.right >= 0) send_keys(effort_log, rels.right, comm);
  }
Exemple #3
0
void symbolic_attacker(int attacker_id, struct keypair* keypair)
  /*@ requires [?f]world(?pub, ?key_clsfy) &*&
               true == bad(attacker_id) &*&
               principal(attacker_id, ?count) &*&
               keypair(keypair, attacker_id, ?id, ?info, pub); @*/
  //@ ensures false;
{
  //@ retreive_proof_obligations();

  for (;;)
    /*@ invariant [f]world(pub, key_clsfy) &*&
                  proof_obligations(pub) &*&
                  principal(attacker_id, _) &*&
                  keypair(keypair, attacker_id, id, info, pub); @*/
  {
    struct network_status *net_stat = 0;
    int net_choise = random_int_();
    int port = random_int_();
    if (net_choise % 2 == 0)
      net_stat = network_bind_and_accept(port % 65536);
    else
      net_stat = network_connect("localhost", port % 65536);

    {
      int action = random_int_();
      int *counter;
      switch (action % 13)
      {
        case 0:
          //@ open [f]world(pub, key_clsfy);
          //@ assert [_]is_key_classifier(_, pub, key_clsfy);
          //@ retreive_public_invariant_constraints(key_clsfy);
          //@ duplicate_lemma_function_pointer_chunk(key_classifier);
          /*@ {
                lemma void public_key_classifier(cryptogram key, int p, int c,
                                                bool symmetric)
                  requires polarssl_proof_pred(pub, key_clsfy)() &*&
                          [_]polarssl_pub(pub)(key) &*&
                          symmetric ?
                            key == cg_symmetric_key(p, c)
                          :
                            key == cg_private_key(p, c);
                  ensures polarssl_proof_pred(pub, key_clsfy)() &*&
                          col || true == key_clsfy(p, c, symmetric);
                {
                  open [_]polarssl_pub(pub)(key);
                  item k;
                  if (symmetric)
                    k = symmetric_key_item(p, c);
                  else
                    k = private_key_item(p, c);
                  
                  open polarssl_proof_pred(pub, key_clsfy)();
                  assert is_key_classifier(?proof, pub, key_clsfy);
                  proof(k, p, c, symmetric);
                  close polarssl_proof_pred(pub, key_clsfy)();
                }
                produce_lemma_function_pointer_chunk(public_key_classifier) :
                  public_key_classifier(polarssl_pub(pub), key_clsfy,
                                        polarssl_proof_pred(pub, key_clsfy))
                                        (key__, p__, c__, sym__)
                  { call(); }
                  {duplicate_lemma_function_pointer_chunk(public_key_classifier);};
              }
          @*/
          //@ close polarssl_proof_pred(pub, key_clsfy)();
          attacker();
          //@ open polarssl_proof_pred(pub, key_clsfy)();
          //@ close [f]world(pub, key_clsfy);
          //@ leak public_invariant_constraints(_, _);
          //@ leak is_public_key_classifier(_, _, _, _);
          //@ leak is_key_classifier(_, _, _);
          break;
        case 1:
          // Anyone can publish arbitrary data items...
          send_data(net_stat);
          break;
        case 2:
          // Anyone can create pairs of public items...
          send_pair_composed(net_stat);
          break;
        case 3:
         // Anyone can deconstruct a public pair...
          send_pair_decomposed(net_stat);
          break;
        case 4:
          // Bad principals can publish generated nonce items...
          send_nonce(net_stat);
          break;
        case 5:
          // Bad principals can increment public nonces...
          increment_and_send_nonce(net_stat);
          break;
        case 6:
          // Bad principals can leak their keys...
          send_keys(net_stat, keypair);
          break;
        case 7:
          // Anyone can hmac public payload with public key
          send_hmac(net_stat, keypair);
          break;
        case 8:
          // Anyone can symmteric encrypt public payload with public key
          send_symmetric_encrypted(net_stat, keypair);
          break;
        case 9:
          // Anyone can symmteric decrypt message with public key
          send_symmetric_decrypted(net_stat, keypair);
          break;
        case 10:
          // Anyone can asymmteric encrypt public payload with public key
          send_asymmetric_encrypted(net_stat, keypair);
          break;
        case 11:
          // Anyone can asymmteric decrypt message with public key
          send_asymmetric_decrypted(net_stat, keypair);
          break;
        case 12:
          // Anyone can asymmteric sign public payload with public key
          send_asymmetric_signature(net_stat, keypair);
      }
    }
    network_disconnect(net_stat);
  }
  //@ leak proof_obligations(pub);
}