Thread: Need help on making dll

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    1

    Need help on making dll

    I am a programmer, but do not know C. I have need of compiling some C code into a dll. I need to know how to access the entry points, etc. What free C compiler would be best to use? Thanksfor any possible help. On PC, I only know Lazarus/Delphi.

    The code is:

    tth.c
    Code:
    /* tth.c - calculate TTH (Tiger Tree Hash) function. */
    
    #include <string.h>
    #include "byte_order.h"
    #include "tth.h"
    /**
     * Initialize context before calculaing hash.
     *
     * @param ctx context to initialize
     */
    void rhash_tth_init(tth_ctx *ctx)
    {
     rhash_tiger_init(&ctx->tiger);
     ctx->tiger.message[ ctx->tiger.length++ ] = 0x00;
     ctx->block_count = 0;
    }
    /**
     * The core transformation.
     *
     * @param ctx algorithm state
     */
    static void rhash_tth_process_block(tth_ctx *ctx)
    {
     uint64_t it;
     unsigned pos = 0;
     unsigned char msg[24];
     for (it = 1; it & ctx->block_count; it <<= 1) {
      rhash_tiger_final(&ctx->tiger, msg);
      rhash_tiger_init(&ctx->tiger);
      ctx->tiger.message[ctx->tiger.length++] = 0x01;
      rhash_tiger_update(&ctx->tiger, (unsigned char*)(ctx->stack + pos), 24);
      /* note: we can cut this step, if the previous rhash_tiger_final saves directly to ctx->tiger.message+25; */
      rhash_tiger_update(&ctx->tiger, msg, 24);
      pos += 3;
     }
     rhash_tiger_final(&ctx->tiger, (unsigned char*)(ctx->stack + pos));
     ctx->block_count++;
    }
    /**
     * Calculate message hash.
     * Can be called repeatedly with chunks of the message to be hashed.
     *
     * @param ctx the algorithm context containing current hashing state
     * @param msg message chunk
     * @param size length of the message chunk
     */
    void rhash_tth_update(tth_ctx *ctx, const unsigned char* msg, size_t size)
    {
     size_t rest = 1025 - (size_t)ctx->tiger.length;
     for (;;) {
      if (size < rest) rest = size;
      rhash_tiger_update(&ctx->tiger, msg, rest);
      msg += rest;
      size -= rest;
      if (ctx->tiger.length < 1025) {
       return;
      }
      /* process block hash */
      rhash_tth_process_block(ctx);
      /* init block hash */
      rhash_tiger_init(&ctx->tiger);
      ctx->tiger.message[ ctx->tiger.length++ ] = 0x00;
      rest = 1024;
     }
    }
    /**
     * Store calculated hash into the given array.
     *
     * @param ctx the algorithm context containing current hashing state
     * @param result calculated hash in binary form
     */
    void rhash_tth_final(tth_ctx *ctx, unsigned char result[24])
    {
     uint64_t it = 1;
     unsigned pos = 0;
     unsigned char msg[24];
     const unsigned char* last_message;
     /* process the bytes left in the context buffer */
     if (ctx->tiger.length > 1 || ctx->block_count == 0) {
      rhash_tth_process_block(ctx);
     }
     for (; it < ctx->block_count && (it & ctx->block_count) == 0; it <<= 1) pos += 3;
     last_message = (unsigned char*)(ctx->stack + pos);
     for (it <<= 1; it <= ctx->block_count; it <<= 1) {
      /* merge TTH sums in the tree */
      pos += 3;
      if (it & ctx->block_count) {
       rhash_tiger_init(&ctx->tiger);
       ctx->tiger.message[ ctx->tiger.length++ ] = 0x01;
       rhash_tiger_update(&ctx->tiger, (unsigned char*)(ctx->stack + pos), 24);
       rhash_tiger_update(&ctx->tiger, last_message, 24);
       rhash_tiger_final(&ctx->tiger, msg);
       last_message = msg;
      }
     }
     /* save result hash */
     memcpy(ctx->tiger.hash, last_message, tiger_hash_length);
     if (result) memcpy(result, last_message, tiger_hash_length);
    }
    
    
    
    tth.h
    
    #ifndef TTH_H
    #define TTH_H
    
    #include "ustd.h"
    #include "tiger.h"
    #ifdef __cplusplus
    extern "C" {
    #endif
    /* algorithm context */
    typedef struct tth_ctx
    {
     tiger_ctx tiger;       /* context used to hash tree leaves */
     uint64_t block_count;  /* number of processed blocks */
     uint64_t stack[64 * 3];
    } tth_ctx;
    /* hash functions */
    void rhash_tth_init(tth_ctx *ctx);
    void rhash_tth_update(tth_ctx *ctx, const unsigned char* msg, size_t size);
    void rhash_tth_final(tth_ctx *ctx, unsigned char result[64]);
    #ifdef __cplusplus
    } /* extern "C" */
    #endif /* __cplusplus */
    #endif /* TTH_H */

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The first thing that would probably pop into anybody's mind is gcc, which you can get from the MinGW project.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-09-2015, 11:07 PM
  2. RPG making tut
    By ExDHaos in forum C++ Programming
    Replies: 2
    Last Post: 05-15-2009, 10:55 PM
  3. Making a .dll
    By ninjaturtle[k9] in forum C++ Programming
    Replies: 7
    Last Post: 07-25-2004, 11:56 PM
  4. making dir
    By chrismiceli in forum C Programming
    Replies: 6
    Last Post: 08-06-2003, 02:05 PM
  5. Replies: 2
    Last Post: 01-13-2003, 01:28 PM

Tags for this Thread