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

  • Home
  • SEARCH
  • 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 7817667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:18:26+00:00 2026-06-02T06:18:26+00:00

I’m trying to make simple library blake hash function wrapper using python ctypes from

  • 0

I’m trying to make simple library blake hash function wrapper using python ctypes from C. But only for testing at first whether my simple C helper function would work correctly or not, I wrote small python script blake hash function test vectors. And my problem arose with this small script. I’m stumbling upon at hours to resolve this problem. I always got unexpected of 64 bytes output value of “blake 512 usage” by using this small helper test vector script. I realize that, my problem is came from c helper function I wrote when trying to return amount of (and should be exact) 64 bytes for later would be used by using this small python ctypes script test vectors.

The pure C implementation source I used was downloaded directly from NIST Blake Submission for Optimiezed 32bit Processor under the name of files, blake_opt32.c and blake_opt32.h . And can be download here at http://csrc.nist.gov/groups/ST/hash/sha-3/Round3/documents/Blake_FinalRnd.zip

And here is my simple C helper function for later to be called by using python ctypes.

#include <stdio.h>
#include "blake_opt32.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <stdint.h>

BitSequence msg[65];

size_t    strlcpy(unsigned char *dst, const char *src, size_t siz)
{
unsigned char *d = dst;
const char *s = src;
size_t n = siz;

/* Copy as many bytes as will fit */
if (n != 0) {
    while (--n != 0) {
        if ((*d++ = *s++) == '\0')
            break;
    }
}

/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
    if (siz != 0)
        *d = '\0';      /* NUL-terminate dst */
    while (*s++)
        ;
}

return(s - src - 1);    /* count does not include NUL */
}

BitSequence * bl(char *input)
{
BitSequence output[65];
BitSequence msg[sizeof(output)];
int dInt;

memset(output,0,sizeof(output));
dInt = strlen(input);

if (dInt > 0xffff){
    exit( 1);
}
BitSequence data[dInt];

memset(data, 0, dInt);
strlcpy(data, input, sizeof(data));
DataLength dLen =1152;
Hash(512, data, dLen, output);
int x;
for (x=0;x<64;++x){
    printf("%02X",output[x]);
}
memcpy(msg,output,sizeof(output));
//here the problem araised, when trying to return unsigned char or BitSequence value, the unexpected output of small python scipt test vectors value is detected 
return  msg; 
}  

And the simple small python script test vector is here, just try this small script by redirecting output to any text of file, later the unexpected value would be catched.

from ctypes import *
from string import printable
from itertools import permutations
from random import *
d = CDLL('blake.dll') #edit here your own dll or .so library
d.bl.restype = c_char_p

print '[+] Simple Test-vectors Blake hash function\n'
s = SystemRandom()
for x in permutations(printable):
p = ''.join(map(str,x))
q = list(p)
s.shuffle(q)
r= d.bl(''.join(map(str,q)))
if ((len(r)*2) != 0x80):
    print '\n[-] Not persistent value of 64 bytes was detected : %d'% len(r) 
    w = r.encode('hex')
    print w, '-->', len(w) 
    print '\n'
elif ((len(r)*2) == 0x80):
    print '\n',len(r), '\n',r.encode('hex')
    print '\n'

Therefore, any corrections of my helper C function above for later to be called using this small Python script test vector in order the output value to be expected would be appreciated, thank you very much before!
By the way above is an updated code.

  • 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-02T06:18:29+00:00Added an answer on June 2, 2026 at 6:18 am

    At the end of the function BitSequence * bl(char *input), The return value output is a local variable that won’t exist after the function exits.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.