<div dir="ltr"><div>I use sha384 through luajit ffi .<br><br><br>local ffi = require "ffi"<br>local ffi_new = ffi.new<br>local ffi_str = ffi.string<br>local C = ffi.C<br>local setmetatable = setmetatable<br>local error = error<br>
<br><br>local _M = { _VERSION = '0.09' }<br><br><br>local mt = { __index = _M }<br><br><br>ffi.cdef[[<br><br>typedef unsigned long SHA_LONG;<br>typedef unsigned long long SHA_LONG64;<br><br>enum {<br> SHA_LBLOCK = 16,<br>
SHA512_CBLOCK = SHA_LBLOCK*8<br>};<br>typedef struct SHA512state_st<br> {<br> SHA_LONG64 h[8];<br> SHA_LONG64 Nl,Nh;<br> union {<br> SHA_LONG64 d[SHA_LBLOCK];<br> unsigned char p[SHA512_CBLOCK];<br>
} u;<br> unsigned int num,md_len;<br> } SHA512_CTX;<br><br>int SHA384_Init(SHA512_CTX *c);<br>int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);<br>int SHA384_Final(unsigned char *md, SHA512_CTX *c);<br>
]]<br><br>local digest_len = 48<br><br>local buf = ffi_new("char[?]", digest_len)<br>local ctx_ptr_type = ffi.typeof("SHA512_CTX[1]")<br><br><br>function _M.new(self)<br> local ctx = ffi_new(ctx_ptr_type)<br>
if C.SHA384_Init(ctx) == 0 then<br> return nil<br> end<br><br> return setmetatable({ _ctx = ctx }, mt)<br>end<br><br><br>function _M.update(self, s)<br> return C.SHA384_Update(self._ctx, s, #s) == 1<br>
end<br><br><br>function _M.final(self)<br> if C.SHA384_Final(buf, self._ctx) == 1 then<br> return ffi_str(buf, digest_len)<br> end<br><br> return nil<br>end<br><br><br>function _M.reset(self)<br> return C.SHA384_Init(self._ctx) == 1<br>
end<br><br><br></div><div>But luajit reports that <br>new() function return nil,that means SHA384_Init() is failed.<br></div><div>The same code in FreeBSD is run OK.<br></div><div>Is this a dragonflybsd issue or luajit issue?<br>
<br>#uname -a<br>DragonFly <a href="http://reli.com">reli.com</a> 3.6-RELEASE DragonFly v3.6.1.22.gcd2a4-RELEASE #0: Sat Mar 29 15:40:48 CST 2014 lhm@reli.com:/usr/obj/usr/src/sys/lhmwzy x86_64<br>#./luajit-2.1.0-alpha<br>
LuaJIT 2.1.0-alpha -- Copyright (C) 2005-2014 Mike Pall. <a href="http://luajit.org/">http://luajit.org/</a><br>JIT: ON SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc sink fuse<br></div></div>