sha512module.c

マクロを分割および関数化に変更

#ifdef PLAN9
void RND(SHA_INT64 *a,SHA_INT64 *b,SHA_INT64 *c,SHA_INT64 *d,SHA_INT64 *e,SHA_INT64 *f,SHA_INT64 *g,SHA_INT64 *h,
		int i,SHA_INT64 ki, SHA_INT64 W[80])
{
	SHA_INT64 t0,t1;

	t0 = *h + Sigma1(*e) + Ch(*e, *f, *g) + ki + W[i];
	t1 = Sigma0(*a);
	t1 += Maj((*a), (*b), (*c));
	*d += t0;
	*h  = t0 + t1;
}
#endif
...
    for (i = 16; i < 80; ++i) {
		W[i] = Gamma1(W[i - 2]);
		W[i] += W[i - 7];
		W[i] += Gamma0(W[i - 15]);
		W[i] += W[i - 16];
    }

sha512

マクロが複雑すぎて、out of fixed registersが出て、sha512はポートできない。
とりあえず、除外しておく。

とおもったら、import shaでこけた。

/* Various logical functions */
#define ROR64(x, y) ?
( ((((x) & Py_ULL(0xFFFFFFFFFFFFFFFF))>>( (unsigned PY_LONG_LONG)(y) & 63)) | ?
*1
#define Ch(x,y,z) (z ^ (x & (y ^ z)))
#define Maj(x,y,z) (((x | y) & z) | (x & y))
#define S(x, n) ROR64( (x),(n))
#define R(x, n) (((x) & Py_ULL(0xFFFFFFFFFFFFFFFF)) >> ( (unsigned PY_LONG_LONG)n))
#define Sigma0(x) (S(x, 28) ^ S(x, 34) ^ S(x, 39))
#define Sigma1(x) (S(x, 14) ^ S(x, 18) ^ S(x, 41))
#define Gamma0(x) (S(x, 1) ^ S(x, 8) ^ R(x, 7))
#define Gamma1(x) (S(x, 19) ^ S(x, 61) ^ R(x, 6))


static void
sha512_transform(SHAobject *sha_info)
{
int i;
SHA_INT64 S[8], W[80], t0, t1;

/* Compress */
#define RND(a,b,c,d,e,f,g,h,i,ki) ?
t0 = h + Sigma1(e) + Ch(e, f, g) + ki + W[i]; ?
t1 = Sigma0(a) + Maj(a, b, c); ?
d += t0; ?
h = t0 + t1;

RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],0,Py_ULL(0x428a2f98d728ae22));

*1:x)<<((unsigned PY_LONG_LONG)(64-((y) & 63))))) & Py_ULL(0xFFFFFFFFFFFFFFFF

configの事

PythonのOS依存部分は、下記の2つ。
PC/config.c
Modules/config.c

いずれもPlan9の場合は
Plan9/config.c
で済ませる

違っているのはこの辺

21,23d20< #ifdef __cplusplus< extern "C" {< #endif
25d21<
41,42d36< extern void init_ast(void);< extern void init_types(void);
64,69d57< /* This lives in Python/Python-ast.c */< {"_ast", init_ast},< < /* This lives in Python/_types.c */< {"_types", init_types},<
82,87d69< < < #ifdef __cplusplus< }< #endif<
20c20< extern void init_md5(void);

    • -

> extern void initmd5(void);
22a23
> extern void initregex(void);
27,29c28< extern void init_sha(void);< extern void init_sha256(void);< extern void init_sha512(void);

    • -

> extern void initsha(void);
30a30
> extern void initstruct(void);
55d54< extern void init_struct(void);
57,58d55< extern void init_functools(void);< extern void initzlib(void);
68,70d64< extern void init_lsprof(void);< extern void init_ast(void);< extern void init_types(void);
81d74< {"_ast", init_ast},
95c88< {"_md5", init_md5},

    • -

> {"md5", initmd5},
97a91
> {"regex", initregex},
102,104c96< {"_sha", init_sha},< {"_sha256", init_sha256},< {"_sha512", init_sha512},

    • -

> {"sha", initsha},
105a98
> {"struct", initstruct},
125d117< {"_lsprof", init_lsprof},
134d125< {"_struct", init_struct},
136d126< {"_functools", init_functools},
140,141c130< {"zlib", initzlib},<

    • -

>
165,166d153< < {"_types", init_types},

mkfile.lib

新しく追加されたモジュールを追加

Python-ast.$O?
asdl.$O?
ast.$O?
exceptions.$O?
codeobject.$O?
_typesmodule.$O?
md5.$O?
posixmodule.$O?

この辺。
posixmoduleがエラーになる。posixでないしな。
struct内のinitstrcutはなくなったようだ