Пример #1
0
/* Add padding and return the message digest. */
static void sha1_final(struct crypto_tfm *tfm, u8 *out)
{
	struct crypt_s390_sha1_ctx *sctx = crypto_tfm_ctx(tfm);

	//must perform manual padding
	pad_message(sctx);
	crypt_s390_kimd(KIMD_SHA_1, sctx->state, sctx->buffer, sctx->buf_len);
	//copy digest to out
	memcpy(out, sctx->state, SHA1_DIGEST_SIZE);
	/* Wipe context */
	memset(sctx, 0, sizeof *sctx);
}
void string_read(char *s)
{
    sha message;
    init(&message);
    int i=0;
    while(s[i]!='\0')
    {
        calculate(&message, s[i]);
        ++i;
    }
    pad_message(&message);
    disp(message);
}
Пример #3
0
static int prepare_index(git_index *index, char* msg){
    git_oid index_tree;
    git_tree *head_obj;
    git_reference *head;
    char tree_str[GIT_OID_HEXSZ+1], parent_str[GIT_OID_HEXSZ+1];

    // Get the head OID
    git_repository_head(&head, repo);
    git_reference_peel((git_object**)&head_obj, head, GIT_OBJ_COMMIT);
    git_oid_tostr(parent_str, GIT_OID_HEXSZ+1,
                   git_tree_id(head_obj));

    git_reference_free(head);
    git_object_free((git_object*)head_obj);

    // Write the coin
    // TODO: Use C for this?
    system("perl -i -pe 's/(null:)(\\d+)/$1 . ($2+1)/e' LEDGER.txt");
    system("grep -q \"null\" LEDGER.txt || echo \"null:1\" >> LEDGER.txt");

    // Update the index
    check_lg2(git_index_read(index, 0),
              "Could not re-read index from disk", NULL);

    check_lg2(git_index_add_bypath(index, "LEDGER.txt"),
              "Could not add to index", "LEDGER.txt");

    // Write the index and get the tree OID
    git_index_write_tree(&index_tree, index);
    git_oid_tostr(tree_str, GIT_OID_HEXSZ+1, &index_tree);

    snprintf(msg, BUFFER_LENGTH,
             "commit %d%c"
             "tree %s\n"
             "parent %s\n"
             "author null           <*****@*****.**> %d +0000\n"
             "committer null           <*****@*****.**> %d +0000\n"
             "\n"
             "coins now"
             "\x01\x01\x01\x01"
             "\x01\x01\x01\x01"
             "\x01\x01\x01", // Align 32 bit words on GPU
             MSG_LENGTH, 0, tree_str, parent_str,
             (int)time(NULL), (int)time(NULL));
    pad_message(msg, COMMIT_LENGTH, BUFFER_LENGTH);

    return 0;
}
Пример #4
0
    /**
     * @param [out] message_digest_array Integer array to store the message in
     * @return Whether or not the extraction was sucessful
     */
    bool get_raw_digest(uint32_t * message_digest_array) {
        if (corrupted) {
            return false;
        }

        if (!computed) {
            pad_message();
            computed = true;
        }

        for (int i = 0; i < 5; i++) {
            message_digest_array[i] = H[i];
        }

        return true;
    }
Пример #5
0
/* Add padding and return the message digest */
static void sha256_final(struct crypto_tfm *tfm, u8 *out)
{
	struct s390_sha256_ctx *sctx = crypto_tfm_ctx(tfm);

	/* must perform manual padding */
	pad_message(sctx);

	crypt_s390_kimd(KIMD_SHA_256, sctx->state, sctx->buf,
			sctx->count / 8);

	/* copy digest to out */
	memcpy(out, sctx->state, SHA256_DIGEST_SIZE);

	/* wipe context */
	memset(sctx, 0, sizeof *sctx);
}
void file_read(char *s)
{
    sha message;
    init(&message);
    FILE *fp;
    fp = fopen(s,"rb");
    char c;
    c = getc(fp);
    while(!feof(fp))
    {
        calculate(&message,c);
        c = getc(fp);
    }
    pad_message(&message);
    disp(message);
    fclose(fp);
}
Пример #7
0
/**************************************************************************
   Description:  This function builds and sends the message with the current
   clutter censor zones.

   Input: file_num - The file number to be edited.

   Output:  Clutter censor zone message.

   Returns: Message sent = 1, Not sent = -1

   Notes:

   **************************************************************************/
static int rms_send_legacy_clutter_zone_msg(ushort file_num)
{
   RPG_clutter_regions_msg_t *clutter_files;
   char                      *Clutter_data;
   UNSIGNED_BYTE             msg_buf[MAX_BUF_SIZE];
   UNSIGNED_BYTE             *msg_buf_ptr;
   int                       msg_length = 0;
   int                       ret, i;
   ushort                    num_halfwords;
   short                     temp_short;

      /* Set pointer to beginning of buffer */
   msg_buf_ptr = msg_buf;

      /* Place pointer past header */
   msg_buf_ptr += MESSAGE_START;

      /* Put file number in output buffer */
   conv_ushort_unsigned(msg_buf_ptr,(ushort*)&file_num);
   msg_buf_ptr += PLUS_SHORT;

      /* Read clutter zone data from clutter zones LB */
   ret = ORPGCCZ_get_censor_zones( ORPGCCZ_LEGACY_ZONES, (char **) &Clutter_data,
                                   ORPGCCZ_DEFAULT );

   if (ret != sizeof (RPG_clutter_regions_msg_t)) {
      LE_send_msg (RMS_LE_ERROR,
         "ORPGCCZ_get_censor_zones failed (ORPGCCZ_LEGACY_ZONES) in edit clutter command (ret %d)",
         ret);
      return(-1);
   }

      /* Assign clutter data to clutter files structure */
   clutter_files = (RPG_clutter_regions_msg_t *) Clutter_data;

      /* Temporarily assigning last file downloaded until coordination 
         with FAA is accomplished */
   file_num = clutter_files->last_dwnld_file;

      /* Place zones in output buffer */
   for (i=0; i<=clutter_files->file[file_num].regions.regions; i++) {

         /* Place start range in message */
      temp_short = clutter_files->file[file_num].regions.data[i].start_range;
      conv_short_unsigned(msg_buf_ptr, &temp_short);
      msg_buf_ptr += PLUS_SHORT;

         /* Place stop range in message */
      temp_short = clutter_files->file[file_num].regions.data[i].stop_range;
      conv_short_unsigned(msg_buf_ptr, &temp_short);
      msg_buf_ptr += PLUS_SHORT;

         /* Place start azimuth in message */
      temp_short =clutter_files->file[file_num].regions.data[i].start_azimuth;
      conv_short_unsigned(msg_buf_ptr, &temp_short);
      msg_buf_ptr += PLUS_SHORT;

         /* Place stop azimuth in message */
      temp_short =clutter_files->file[file_num].regions.data[i].stop_azimuth;
      conv_short_unsigned(msg_buf_ptr, &temp_short);
      msg_buf_ptr += PLUS_SHORT;

         /* Place segment number in message */
      temp_short =clutter_files->file[file_num].regions.data[i].segment;
      conv_short_unsigned(msg_buf_ptr, &temp_short);
      msg_buf_ptr += PLUS_SHORT;

         /* Place select code in message */
      temp_short =clutter_files->file[file_num].regions.data[i].select_code;
      conv_short_unsigned(msg_buf_ptr, &temp_short);
      msg_buf_ptr += PLUS_SHORT;

         /* Place doppler level in message */
      temp_short =clutter_files->file[file_num].regions.data[i].doppl_level;
      conv_short_unsigned(msg_buf_ptr, &temp_short);
      msg_buf_ptr += PLUS_SHORT;


         /* Place surviellance level in message */
      temp_short =clutter_files->file[file_num].regions.data[i].surv_level;
      conv_short_unsigned(msg_buf_ptr, &temp_short);
      msg_buf_ptr += PLUS_SHORT;

   } /* End for loop */

      /* Pad the message if necessary */
   if (i < MAX_NUMBER_CLUTTER_ZONES) {
      msg_length = msg_buf_ptr - msg_buf;
      pad_message(msg_buf_ptr, msg_length, MAX_CLUTTER_LENGTH);
   }

      /* Place pointer to end of message */
   msg_buf_ptr += (MAX_CLUTTER_LENGTH - msg_length);

      /* Add terminator to the message */
   add_terminator(msg_buf_ptr);
   msg_buf_ptr += PLUS_INT;

      /* Compute the number of halfwords in the message */
   num_halfwords = ((msg_buf_ptr - msg_buf) / 2);

      /* Add header to message */
   ret = build_header(&num_halfwords, STATUS_TYPE, msg_buf, 0);

   if (ret != 1){
      LE_send_msg (RMS_LE_ERROR,
         "Build RMMS msg header failed for clutter censor zone");
      return (-1);
   }

      /* Send the message to the FAA/RMMS */
   ret = send_message(msg_buf,STATUS_TYPE,RMS_STANDARD);

   if (ret != 1){
      LE_send_msg (RMS_LE_ERROR,
         "Send RMMS message failed (ret %d) for clutter censor zones", ret);
      return (-1);
   }

      /* Lock the clutter zone msg so someone else cannot 
         edit until RMS is done */
   ret = ORPGCCZ_set_edit_lock( ORPGCCZ_LEGACY_ZONES );

   if ( ret == ORPGEDLOCK_LOCK_UNSUCCESSFUL) {
      LE_send_msg(RMS_LE_ERROR,"Unable to lock CENSOR ZONES LGCY");
      return (ret);
   } else{
      LE_send_msg(RMS_LE_ERROR,"CENSOR ZONES LGCY locked");
      clutter_zones_locked = 1;
   }

   return (1);

} /*End build clutter */
Пример #8
0
int main(int argc, char **argv){
    int i, j;
    char unused_stop = 0;
    int iters = 10;
    hash_args args;
    char msg[BUFFER_LENGTH];
    unsigned char hash[SHA_DIGEST_LENGTH];
    char hex_hash[SHA_DIGEST_LENGTH*2];
    char hex_difficulty[SHA_DIGEST_LENGTH*2] = "00000008ffffffffffffffffffffffffffffffff";
    unsigned char difficulty;

    struct timeval start, end, diff;
    unsigned long total = 0, curr;

    // Fill in some deterministic data
    for(i = 0; i < BUFFER_LENGTH; i++){
        msg[i] = i % 128;
    }

    pad_message(msg, COMMIT_LENGTH, BUFFER_LENGTH);

    args.stop = &unused_stop;
    args.msg = (char*)msg;

    if(argc > 1){
        iters = atoi(argv[1]);
    }

    if(argc > 2){
        memcpy(hex_difficulty, argv[2], SHA_DIGEST_LENGTH*2);
    }

    difficulty = parse_difficulty(hex_difficulty);
    printf("Starting benchmark with difficulty %02x\n", difficulty);

    init_hasher(difficulty);

    for(i = 0; i < iters; i++){
        memset(msg, 0, COMMIT_LENGTH);
        *((int*)(&(msg[0]))) = i;
        args.found = 0;

        cudaProfilerStart();
        gettimeofday(&start, NULL);
        force_hash(&args);
        gettimeofday(&end, NULL);
        cudaProfilerStop();

        timersub(&end, &start, &diff);
        curr = diff.tv_sec * 1000 + diff.tv_usec / 1000;
        total += curr;

        SHA1(msg, COMMIT_LENGTH, hash);

        for(j=0; j < 20; j++){
            sprintf(&hex_hash[j*2], "%02x", hash[j] & 0xff);
        }

        if(memcmp(hex_hash, hex_difficulty, SHA_DIGEST_LENGTH*2) > 0){
            printf("Msg:");
            for(j = 0; j < BUFFER_LENGTH; j++){
                printf("%02x", msg[j] & 0xff);
            }

            printf("\nBad hash: %.40s\n", hex_hash);
            exit(1);
        } else {
            printf("Successful run in %ld ms: %.40s\n", curr, hex_hash);
        }

        if(!args.found){
            puts("Failed to find a hash!");
            exit(1);
        }
        printf("\n");
    }

    printf("\n%ld ms per iteration (%d iters, %.40s difficulty)\n",
           total / iters,
           iters, hex_difficulty);

    free_hasher();

    exit(0);
}
Пример #9
0
void rms_send_free_text_msg () {

   UNSIGNED_BYTE free_text_buf[MAX_BUF_SIZE];
   UNSIGNED_BYTE *free_text_buf_ptr;
   char          *Msg;
   int           ret, i, msg_size;
   LB_info       info;
   ushort        message_size_halfwords, num_halfwords;

   /* Search for the latest free text message. */
   if((ret = ORPGDA_seek(ORPGDAT_RMS_TEXT_MSG, 0, LB_LATEST, &info)) < 0) {
       LE_send_msg(RMS_LE_ERROR, "Failed seek RMMS free text message (%d).\n", ret );
   }else {

      /* Allocate memory for the message. */
      Msg = (char*)malloc(info.size);

      /* Read the latest message. */
      ret = ORPGDA_read (ORPGDAT_RMS_TEXT_MSG, (char *) Msg, info.size, info.id);

      if(ret <0 ){
         LE_send_msg(RMS_LE_ERROR, "Failed read RMMS free text message (%d).\n", ret );
      }else {
         /* Set the pointer to beginning of buffer */
         free_text_buf_ptr = free_text_buf;

         /* Set the pointer past the header */
         free_text_buf_ptr += MESSAGE_START;

         /* Compute the size of the free text string in halfwords */
         message_size_halfwords = (info.size/2);

         /* Adjust for rounding */
         message_size_halfwords += (info.size%2);

         /* Put free text string size in output buffer */
          conv_ushort_unsigned(free_text_buf_ptr,&message_size_halfwords);
         free_text_buf_ptr += PLUS_SHORT;

         /* Put free text string in output buffer */
         for (i=0; i< info.size; i++){
            conv_char_unsigned(free_text_buf_ptr, &Msg[i], PLUS_BYTE);
            free_text_buf_ptr += PLUS_BYTE;
         } /* End loop */

         /* Compute the size of the message */
         msg_size = (free_text_buf_ptr - free_text_buf);

         /* Pad the message */
         pad_message (free_text_buf_ptr, msg_size, TEXT_PAD_SIZE);
         free_text_buf_ptr += (TEXT_PAD_SIZE - msg_size);

         /* Add the terminator to the message */
         add_terminator(free_text_buf_ptr);
         free_text_buf_ptr += PLUS_INT;

         /* Compute the size of the message in halfwords */
         num_halfwords = ((free_text_buf_ptr - free_text_buf) / 2);

         /* Add header to message */
         ret = build_header(&num_halfwords, FREE_TYPE, free_text_buf, 0);

         if (ret != 1){
            LE_send_msg (RMS_LE_ERROR,
            "RMS build header failed for rms send free text message");
         } /* End if */

         /* Send message to the FAA/RMMs */
         ret = send_message(free_text_buf,FREE_TYPE,RMS_STANDARD);

         if (ret != 1){
            LE_send_msg (RMS_LE_ERROR,
            "Send message failed (ret %d) for rms send free text message", ret);
         }  /* end if */
      } /* End else */

      free(Msg);

   } /* End else */

} /*End rms send free text msg */
Пример #10
0
#include "../src/common.h"
#include "../src/hash.h"

TEST_CASE("Test message padding", "[hash]")
  {
  message_t message_1(8, 0xff); // should pad to 16 bytes
  message_t message_2(16, 0xff); // should pad to 24 bytes

  message_t message_3(13, 0xff); // should pad to 16 bytes
  message_t message_4(17, 0xff); // should pad to 24 bytes


  SECTION("Pads if message length divides by 8 bytes")
    {
    REQUIRE(pad_message(message_1).size() == 16);
    REQUIRE(pad_message(message_2).size() == 24);
    }

  SECTION("Pads if message length does not divide by 8 bytes")
    {
    REQUIRE(pad_message(message_3).size() == 16);
    REQUIRE(pad_message(message_4).size() == 24);
    }

  SECTION("Adds correct padding bits")
    {
    REQUIRE(pad_message(message_1)[8] == 0x80);
    REQUIRE(pad_message(message_4)[17] == 0x80);
    }
  }