Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8617059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:46:02+00:00 2026-06-12T05:46:02+00:00

I have two uint8_t pointers in my program and I want to compare the

  • 0

I have two uint8_t pointers in my program and I want to compare the values of those. I don’t have good idea to deal with unsigned ints. Here is my code

static void bacast_signed_message()
{
  uint8_t *M = malloc(MAX_M_LEN*sizeof(uint8_t));//uint8_t M[MAX_M_LEN];//uint8_t *M;
  int M_len = MAX_M_LEN;;

  uint8_t *C = malloc((2*KEYDIGITS*NN_DIGIT_LEN + 1 + MAX_M_LEN + HMAC_LEN)*sizeof(uint8_t));   
  int C_len; 
  //uint8_t C[2*KEYDIGITS*NN_DIGIT_LEN + 1 + MAX_M_LEN + HMAC_LEN]; 

  uint8_t *dM = malloc(MAX_M_LEN*sizeof(uint8_t));  //uint8_t dM[MAX_M_LEN];
  int dM_len = MAX_M_LEN;

  random_data(M, MAX_M_LEN);

  printf("C before encrypt %p\n",*C);
  printf("M before encrypt %p\n",*M);
  printf("dM before encrypt %p\n",*dM);

  C_len = encrypt(C, (2*KEYDIGITS*NN_DIGIT_LEN + 1 + M_len + HMAC_LEN), M, M_len, &pbkey_alice);
  //encrypt(uint8_t *C, int C_len, uint8_t *M, int M_len, Point *PublicKey);

  printf("C after encrypt %p\n",*C);
  printf("M after encrypt %p\n",*M);
  printf("dM after encrypt %p\n",*dM);

  dM_len = decrypt(dM, dM_len, C, C_len, prKey_alice);   
  //decrypt(uint8_t *M, int M_len, uint8_t *C, int C_len, NN_DIGIT *d);

  printf("C after decrypt %p\n",*C);
  printf("M after decrypt %p\n",*M);
  printf("dM after decrypt %p\n",*dM);

  printf("C_len = %i , M_len = %i\n",C_len,M_len);

  if (dM == M){printf("Works\n");}
  else{printf("Not Works\n");}
}

and this is the out put I got

C before encrypt 0x40
M before encrypt 0x28
dM before encrypt 0x70
C after encrypt 0x4
M after encrypt 0x28
dM after encrypt 0x70
C after decrypt 0x4
M after decrypt 0x28
dM after decrypt 0x28
C_len = 102 , M_len = 41
Not Works

And if I changed private_key(no change of public key) then It looks like this

C before encrypt 0x40
M before encrypt 0x28
dM before encrypt 0x70
C after encrypt 0x4
M after encrypt 0x28
dM after encrypt 0x70
C after decrypt 0x4
M after decrypt 0x28
dM after decrypt 0x70
C_len = 102 , M_len = 41
Not Works

That mean dM has not changed no. But I am not sure about this. If I use %u instead of %p it will give me totally different answers(it says if we use %u it’ll convert to decimal). Please give me some advice, and tell me whats wrong with this.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:46:03+00:00Added an answer on June 12, 2026 at 5:46 am

    Possible ways to understand your question

    Your code if (dM == M) currently compares pointers. So you’re currently checking whether or not the two pointers indicate the same chunk of memory.

    Your question title suggests that you want to compare single numbers. After all, an uint8_t is just a single number in the range 0 – 255. If you have pointers to such numbers, you’d have to dereference them to get at the actual numbers, like if (*dM == *M).

    But your code suggests that you actually want to compare memory regions. Dereferencing a pointer to an array is the same as accessing the first element of the array (i.e. the same as if (dM[0] == M[0])), which probably is not what you want.

    Comparing memory regions

    You can use memcmp to compare the content of memory regions:

    if (dM_len == M_len && memcmp(dM, M, dM_len) == 0)
    

    This means “if the lengths are the same, and the content of the two memory regions is the same as well”. If the result of memcmp is nonzero, its sign provides information as to which value is considered greater.

    Printing

    Note that the %p in your printf calls is probably wrong: %p is for printing pointers, but as you’re dereferencing them in the function call, you’re actually printing values. So %u is much more suitable. If you want to print the content of e.g. M, you’ll have to use a loop like this:

    for (i = 0; i != M_len; ++i) {
      if (i%32 == 0 && i != 0) printf("\n"); /* wrap lines */
      printf("%02x", M[i]);
    }
    printf("\n");
    

    This will print a hexadecimal representation of your data, with 32 bytes (= 64 hexadecimal digits) per line. The %02x format instructs printf to allways use two digits for every byte, padding with zero as required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two update panels on a page. And I want to update both
Say I have these two variables: size_t value; size_t size; And I want to
I have a boost recursive variant as below. When I compare two recursive variant
i have to event that should insert values in two vectors but when event
Have two folders with approx. 150 java property files. In a shell script, how
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two tables images2 and image_data So the goal is to have 1
I have two classes (MVC view model) which inherits from one abstract base class.
I have two files client.php and server.php. The client file send a HTTP request
I have two columns say Main and Sub . (they can be of same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.