📄 example.ps
字号:
AC171F6D6D1480A2173F6D16006F5B6D6D137E6D6D5B6DEBFF836EEBFFF86E5C020F14C002035C9126003FFCC7FC325C7DDA3F>I<007FB600C0017FB512F8A6D8001F01F8C70007EBF0006D040190C7FC6D6D5D6D6D4A5A6D6D4A5A70495A6D4C5A6E7F6E6D495A6E6D495A7049C8FC6E4A5A6E6D485A6E6D485A6E13FFEF8FF06EEC9FE06FEBFFC06F5C6F91C9FC5F6F5B816F7F6F7F8481707F8493B57E4B805D4B80DB0FF37FDB1FE17F04C080153F4B486C7F4B486C7F4A486D7F4A486D7F4A5A4B6D7F020F6E7F4A486D7F4A486D804A5A4AC86C7F49486F7F4A6F7F0107707FEB3FFFB600F049B7FCA650407EBF55>120D E%EndDVIPSBitmapFontend%%EndProlog%%BeginSetup%%Feature: *Resolution 600dpiTeXDict begin%%BeginPaperSize: a4a4%%EndPaperSize%%EndSetup%%Page: 1 11 0 bop 692 456 a Fj(An)53 b(Example)h(of)g(Using)g(the)f(ECC-LIB)393708 y Fi(Elisa)m(v)m(et)33 b(Konstan)m(tinou)1339 672y Fh(\003)1594 708 y Fi(Yiannis)e(Stamatiou)2421 672y Fh(y)2676 708 y Fi(Christos)i(Zaroliagis)3507 672 yFh(y)1629 912 y Fi(August)g(1,)f(2002)141 1261 y Fg(W)-8b(e)47 b(illustrate)c(the)i(simplicit)m(y)e(and)h(ease)j(of)e(use)g(of)g(ecc-lib)g(b)m(y)g(presen)m(ting)f(a)i(small)d(program)i(that)01374 y(generates)32 b(a)f(digital)d(signature)i(using)f(the)h(Elliptic)e(Curv)m(e)i(Digital)g(Signature)f(Algorithm)g(\(ECDSA\).)1411487 y(A)24 b(digital)e(signature)h(is)g(a)h(pair)f(of)g(in)m(tegers)h(\()p Ff(r)s Fg(,)i Ff(s)p Fg(\))d(whose)h(v)-5 b(alues)23b(dep)s(end)f(b)s(oth)h(on)g(the)h(message)h(that)f(is)f(to)01600 y(b)s(e)j(signed)f(and)h(the)h(priv)-5 b(ate)26b(k)m(ey)h(of)g(the)g(signer.)38 b(The)26 b(receiv)m(er)h(of)g(the)f(signature)g(m)m(ust)h(b)s(e)e(able)i(to)g(v)m(erify)f(the)01713 y(message.)42 b(A)30 b(v)m(ery)h(p)s(opular)d(sc)m(heme)j(that)g(can)g(b)s(e)e(used)h(for)g(creating)h(an)f(elliptic)e(curv)m(e)i(signature)g(proto)s(col)0 1826 y(is)h(the)h(Elliptic)e(Curv)m(e)h(Digital)h(Signature)f(Algorithm.)44 b(In)32 b(order)f(to)i(create)h(the)e(signature,)g(the)h(user)e(m)m(ust)0 1939 y(\014rstly)i(generate)j(the)f(prime)e(order)h Ff(p)g Fg(of)h(the)f(\014nite)g(\014eld,)g(the)h(elliptic)d(curv)m(e)j(and)f(its)f(order)h Ff(m)p Fg(.)53b(Secondly)-8 b(,)0 2051 y(the)30 b(user)g(m)m(ust)g(create)i(a)e(base)h(p)s(oin)m(t)e(whic)m(h)g(is)g(used)g(to)i(generate)h(a)f(pair)e(of)h(k)m(eys)h(\(priv)-5 b(ate)30 b(and)f(public\).)39 b(In)02164 y(particular,)32 b(only)h(the)g(priv)-5 b(ate)33b(k)m(ey)h(will)c(b)s(e)j(used)f(in)g(the)i(creation)f(of)h(the)f(signature.)49 b(The)32 b(function)g(whic)m(h)0 2277y(will)22 b(actually)i(pro)s(duce)g(the)h(signature)f(tak)m(es)i(as)f(input)e(the)i(computed)f(order)g Ff(p)p Fg(,)i(the)f(elliptic)e(curv)m(e,)j(the)f(large)0 2390 y(prime)31 b(factor)i Ff(n)eFg(of)i Ff(m)p Fg(,)f(the)h(base)f(p)s(oin)m(t,)g(the)g(priv)-5b(ate)32 b(k)m(ey)-8 b(,)34 b(and)e(of)g(course)g(the)h(message)g(\(or)g(the)f(\014le\))g(to)h(b)s(e)0 2503 y(signed.)39 b(The)27b(details)g(of)h(the)g(generation)g(of)g(a)g(signature)f(o)m(v)m(er)i(a)f(\014le)f(are)h(explained)e(in)h(the)h(follo)m(wing)e(simple)02616 y(program.)0 2941 y Fe(#include)46 b(<stdio.h>)03054 y(#include)g(<stdlib.h>)0 3167 y(#include)g(<unistd.h>)03393 y(#include)g("gmp.h")0 3619 y(#include)g("cm.h")03732 y(#include)g("ec_operations.h")0 3845 y(#include)g("protocols.h")04071 y(gmp_randstate_t)e(stat;)0 4296 y(int)j(main\(\))04409 y({)48 4522 y(/*)g(Initialize)e(all)i(the)g(necessary)e(variables)g(*/)48 4635 y(/*)i(Initialize)e(the)i(seed)f(for)h(the)g(random)f(number)g(generator)g(*/)48 4748 y(/*)h(Create)f(the)h(elliptic)e(curve)i(parameters)e(*/)48 4861 y(/*)i(Sign)g(the)f(file)h(*/)484974 y(/*)g(Clear)f(all)h(the)g(variables)e(*/)48 5200y(return)h(0;)0 5313 y(})p 0 5382 1560 4 v 102 5435 aFd(\003)138 5467 y Fc(Computer)27 b(T)-6 b(ec)n(hnology)28b(Institute)f(and)g(Departmen)n(t)f(of)i(Computer)f(Engineering)h(&)f(Informatics,)i(Univ)n(ersit)n(y)d(of)j(P)n(atras,)05558 y(26500)f(P)n(atras,)f(Greece.)35 b(E-mails:)g Fb(f)pFa(konstane,stamatiu,zaro)p Fb(g)p Fa(@ceid)q(.upa)q(tras.)q(gr)pFc(.)1927 5825 y Fg(1)p eop%%Page: 2 22 1 bop 141 304 a Fg(The)39 b(\014les)g Fe(cm.h)p Fg(,)hFe(ec)p 888 304 29 4 v 34 w(operations.h)c Fg(and)j Fe(protocols.h)eFg(are)j(included)c(in)i(the)i(program,)i(since)d(they)0417 y(con)m(tain)g(the)g(functions)e(of)i(ecc-lib)f(that)i(will)c(b)s(e)i(used)g(in)f(the)i(program.)66 b(Also,)41 b(the)e(\014le)fFe(gmp.h)f Fg(m)m(ust)i(b)s(e)0 530 y(included)31 b(b)s(ecause)k(the)f(GNUMP)h(library)c(is)j(used)f(for)h(the)g(computations.)52b(Finally)-8 b(,)34 b(the)g(v)-5 b(ariable)33 b Fe(stat)gFg(is)0 643 y(de\014ned)c(globally)g(as)i(it)f(is)f(used)h(b)m(y)g(all)f(functions)g(that)i(generate)h(random)d(n)m(um)m(b)s(ers.)141756 y(The)h(ECDSA)g(program)g(consists)g(of)g(\014v)m(e)h(parts)f(of)h(the)f(program)g(that)h(are)g(describ)s(ed)d(in)i(the)g(follo)m(wing.)141 868 y(The)g(\014rst)g(part)g(\(initialization)e(step\))i(is)g(implemen)m(ted)f(as)h(follo)m(ws:)286 1194 y Fe(/*)48b(Initialization)43 b(*/)286 1307 y(long)k(D,)g(sd)g(=)h(0;)2861533 y(mpz_t)f(p,)g(m,)g(n,)g(h,)g(private_key;)286 1645y(mpz_t)g(curv[2],)e(base_point[2],)f(public_key[2];)2861758 y(mpz_t)j(seed;)286 1984 y(gmp_randinit\(stat,)c(GMP_RAND_ALG_LC,)h(120\);)286 2210 y(mpz_init\(p\);)286 2323 y(mpz_init\(m\);)2862436 y(mpz_init\(n\);)286 2549 y(mpz_init\(h\);)286 2662y(mpz_init\(private_key\);)286 2775 y(mpz_init\(curv[0]\);)f(mpz_init\(curv[1]\);)286 2888 y(mpz_init\(base_point[0]\);)f(mpz_init\(base_point[1]\))o(;)286 3000 y(mpz_init\(public_key[0]\);)g(mpz_init\(public_key[1]\))o(;)286 3113 y(mpz_init\(seed\);)1413439 y Fg(The)33 b(v)-5 b(ariables)32 b Fe(p,m)g Fg(and)hFe(private)p 1409 3439 V 32 w(key)g Fg(store)g(the)h(\014eld's)e(order,)h(the)h(EC's)f(order)f Ff(m)p Fg(,)i(and)f(the)g(priv)-5b(ate)0 3552 y(k)m(ey)39 b(of)g(the)g(signer,)h(resp)s(ectiv)m(ely)-8b(,)40 b(while)d(the)h(v)-5 b(ariables)38 b Fe(curv,)46b(base)p 2551 3552 V 33 w(point)37 b Fg(and)h Fe(public)p3334 3552 V 33 w(key)g Fg(store)h(the)0 3665 y(elliptic)31b(curv)m(e's)i(parameters)h Ff(a)f Fg(and)f Ff(b)h Fg(\(in)fFe(curv[0])f Fg(and)i Fe(curv[1])p Fg(,)f(resp.\),)i(the)f(co)s(ordinates)g(\()p Ff(x;)15 b(y)s Fg(\))34 b(of)f(the)03778 y(base)40 b(p)s(oin)m(t)f(of)h(the)g(EC)f(\(in)gFe(base)p 1254 3778 V 33 w(point[0])e Fg(and)i Fe(base)p2086 3778 V 34 w(point[1])p Fg(,)h(resp.\),)i(and)d(the)h(public)d(k)m(ey)k(of)f(the)0 3890 y(signer.)f(All)27 b(the)h(v)-5b(ariables)27 b(are)h(initialized)d(with)i(the)h(function)fFe(mpz)p 2403 3890 V 33 w(init\(\))g Fg(of)h(the)g(GNUMP)h(library)-8b(,)27 b(while)0 4003 y(the)k(random)e(state)j(v)-5 b(ariable)29b Fe(stat)g Fg(is)h(initiallized)c(with)j(the)i(function)eFe(gmp)p 2681 4003 V 33 w(randinit\(\))p Fg(.)141 4116y(The)h(second)h(part)f(concerns)h(the)g(assignmen)m(t)f(of)h(an)g(initial)d(v)-5 b(alue)30 b(to)h(the)g(random)f(state)i(v)-5b(ariable)29 b Fe(stat)0 4229 y Fg(with)g(the)i(help)e(of)h(a)h(seed:)286 4442 y Fe(/*)48 b(Initialize)d(the)h(random)h(state)f(variable)f(stat)i(*/)286 4555 y(srand\()f(\(unsigned\))f(getpid\(\)\);)2864667 y(sd=rand\(\);)286 4780 y(mpz_set_ui\(seed,)f(sd\);)2865006 y(gmp_randseed\(stat,)f(seed\);)141 5219 y Fg(The)38b(function)f Fe(gmp)p 850 5219 V 34 w(randseed\(\))eFg(sets)k(the)g(initial)d(seed)i(v)-5 b(alue,)41 b(generated)e(b)m(y)f(the)h(ANSI)f(C)g(function)0 5332 y Fe(rand\(\))p Fg(.)1415445 y(The)30 b(third)f(part)h(concerns)g(the)h(creation)g(of)f(the)h(elliptic)d(curv)m(e)i(parameters.)1927 5825 y(2)p eop%%Page: 3 33 2 bop 286 91 a Fe(/*)48 b(set)e(the)h(value)g(of)g(the)g(discriminant*/)286 204 y(D)h(=)f(40;)286 430 y(/*)h(create)e(the)h(order)f(p,)h(the)g(elliptic)f(curve)g(and)h(its)g(order)f(m)i(using)e(D)h(*/)286 543 y(CMmethod\(D,)e(&p,)i(&m,)g(curv\);)286769 y(/*)h(create)e(a)h(base)g(point)f(of)h(order)g(n,)g(where)f(m)i(=)f(nh)g(and)g(returns)f(n)h(and)g(h*/)286 882 y(domain_parameters\(curv,)42 b(base_point,)j(&p,)h(&m,)h(&n,)g(&h\);)286 1108 y(/*)h(create)e(a)h(private)f(and)h(a)g(public)f(key)h(*/)2861220 y(create_priv_and_public\(cur)o(v,)41 b(&p,)47 b(base_point,)e(&private_key,)f(public_key\);)141 1433 y Fg(The)32 b(function)fFe(CMmethod\(\))f Fg(\(de\014ned)h(in)h Fe(cm.h)p Fg(\))f(tak)m(es)j(as)f(input)d(the)j(discriminan)m(t)d Ff(D)35 b Fg(\(w)m(e)e(ga)m(v)m(e)i(it)d(the)0 1546 y(v)-5 b(alue)38 b(40\))h(and)f(pro)s(duces)e(the)j(\014eld's)e(order)g Ff(p)p Fg(,)j(the)f(parameters)fFf(a)g Fg(and)g Ff(b)g Fg(of)g(the)h(EC,)f(and)f(the)i(order)eFf(m)0 1659 y Fg(of)31 b(the)g(EC.)f(The)g(function)fFe(domain)p 1281 1659 29 4 v 33 w(parameters\(\))e Fg(\(de\014ned)j(in)g Fe(ec)p 2469 1659 V 33 w(operations.h)p Fg(\))e(constructs)j(the)g(base)0 1772 y(p)s(oin)m(t)f(of)i(the)f(EC)g(whic)m(h)f(has)h(order)gFf(n)p Fg(,)h(where)e Ff(n)h Fg(is)g(the)g(large)h(prime)d(factor)k(of)e Ff(m)p Fg(,)h(and)f(computes)g(the)h(t)m(w)m(o)0 1885y(factors)k Ff(n)e Fg(and)h Ff(h)p Fg(.)54 b(Finally)-8b(,)35 b(the)g(function)f Fe(create)p 1852 1885 V 33w(priv)p 2077 1885 V 33 w(and)p 2254 1885 V 34 w(public\(\))eFg(\(de\014ned)i(in)g Fe(ec)p 3264 1885 V 34 w(operations.h)pFg(\))0 1998 y(pro)s(duces)e(the)i(public)d(and)i(priv)-5b(ate)33 b(k)m(eys)h(of)g(the)f(signer)g(based)g(on)h(the)f(constructed)h(EC,)f(the)h(\014eld's)e(order)0 2110 yFf(p)p Fg(,)e(and)g(the)h(computed)f(base)g(p)s(oin)m(t.)1412223 y(The)g(fourth)g(part)g(concerns)g(the)h(generation)f(of)h(the)g(signature)e(on)i(the)f(\014le)g Fe(README)p Fg(.)1912436 y Fe(/*)47 b(generate)f(the)h(signature)e(on)i(the)g(file)g(README)f(using)g(ECDSA)334 2549 y(the)h(signature)e(is)i(stored)g(in)g(the)g(file)f(signature)g(*/)286 2662 y(file_create_signature\("REA)o(DME)o(",)c(curv,)k(base_point,)f(&p,)i(&n,)g(&private_key,)d("signature"\);)141 2874 y Fg(The)24 b(function)g Fe(file)p871 2874 V 33 w(create)p 1192 2874 V 33 w(signature\(\))dFg(\(de\014ned)j(in)g Fe(protocols.h)p Fg(\))e(generates)k(the)f(requested)f(pair)0 2987 y(of)33 b(in)m(tegers)h(\()pFf(r)m(;)15 b(s)p Fg(\))34 b(\(and)g(store)f(them)h(in)e(a)h(\014le\))g(using)f(the)h(ECDS)g(Algorithm,)g(taking)g(as)h(input)d(the)j(\014le)e(to)0 3100 y(b)s(e)e(signed,)f(the)i(EC,)f Ff(p)p Fg(,)g(the)h(base)f(p)s(oin)m(t,)g(the)g(prime)f(factor)j(of)e Ff(m)p Fg(,)h(and)e(the)i(priv)-5 b(ate)30 b(k)m(ey)h(of)f(the)h(signer.)141 3213y(The)41 b(\014fth)g(part)g(of)h(the)f(program)h(clears)f(the)h(used)f(v)-5 b(ariables)40 b(whic)m(h)g(is)h(requested)g(b)m(y)g(the)h(GNUMP)03326 y(library)-8 b(.)286 3538 y Fe(gmp_randclear\(stat\);)2863651 y(mpz_clear\(p\);)286 3764 y(mpz_clear\(m\);)2863877 y(mpz_clear\(n\);)286 3990 y(mpz_clear\(h\);)2864103 y(mpz_clear\(private_key\);)286 4216 y(mpz_clear\(curv[0]\);)43b(mpz_clear\(curv[1]\);)286 4329 y(mpz_clear\(base_point[0]\);)e(mpz_clear\(base_point[1]\);)286 4442 y(mpz_clear\(public_key[0]\);)g(mpz_clear\(public_key[1]\);)286 4555 y(mpz_clear\(seed\);)19275825 y Fg(3)p eop%%Trailerenduserdict /end-hook known{end-hook}if%%EOF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -