Git Product home page Git Product logo

crypt-cpace's Introduction

NAME

Crypt::CPace

PROTOCOL

https://datatracker.ietf.org/doc/draft-irtf-cfrg-cpace/

EXAMPLE

use Crypt::OpenSSL::EC;
use Crypt::OpenSSL::Hash2Curve qw/expand_message_xmd/;
use Crypt::CPace ;

# a, b with same info
my $PRS = 'Password';
my $sid = pack("H*", "34b36454cab2e7842c389f7d88ecb7df");

my $DSI = 'CPaceP256_XMD:SHA-256_SSWU_NU_';
my $CI= "\nAinitiator\nBresponder";
my $group_name = 'prime256v1';
my $type = 'sswu';
my $hash_name = 'SHA256';

# a, b calculate_generator G
my ($G, $params_ref) = calculate_generator($DSI, $PRS, $CI, $sid, $group_name, $type, $hash_name, \&expand_message_xmd, 1);
my ($group, $c1, $c2, $p, $a, $b, $z, $ctx) = @$params_ref;
my $G_hex = Crypt::OpenSSL::EC::EC_POINT::point2hex($group, $G, 4, $ctx);
print "G=", $G_hex, "\n\n";

# a send MSGa
my $ADa  = "ADa";
my $ya;
my $Ya;
my $MSGa;
($MSGa, $Ya, $ya) = prepare_send_msg($group, $G, $ya, 4, $ctx, $ADa);
print "ya=", $ya->to_hex(), "\n";
print "Ya=", Crypt::OpenSSL::EC::EC_POINT::point2hex($group, $Ya, 4, $ctx), "\n";
print "MSGa: ", unpack( "H*", $MSGa ), "\n\n";

# b send Msgb
my $ADb  = "ADb";
my $yb;
my $Yb;
my $MSGb;
($MSGb, $Yb, $yb) = prepare_send_msg($group, $G, $yb, 4, $ctx, $ADb);
print "yb=", $yb->to_hex(), "\n";
print "Yb=", Crypt::OpenSSL::EC::EC_POINT::point2hex($group, $Yb, 4, $ctx), "\n";
print "MSGb: ", unpack( "H*", $MSGb ), "\n\n";

# a recv Msgb, calc ISK
my $ISKa_order = prepare_ISK($DSI, $sid, $group, $ya, $MSGa, $MSGb, 1, 0, 'SHA256', $ctx);
print "order isk a: ", unpack("H*", $ISKa_order), "\n";

my $ISKa_unorder = prepare_ISK($DSI, $sid, $group, $ya, $MSGa, $MSGb, 1, 1, 'SHA256', $ctx);
print "unorder isk: ", unpack("H*", $ISKa_unorder), "\n\n";

# b recv Msga, calc ISK
my $ISKb_order = prepare_ISK($DSI, $sid, $group, $yb, $MSGb, $MSGa, 0, 0, 'SHA256', $ctx);
print "order isk b: ", unpack("H*", $ISKb_order), "\n";

my $ISKb_unorder = prepare_ISK($DSI, $sid, $group, $yb, $MSGb, $MSGa, 0, 1, 'SHA256', $ctx);
print "unorder isk b: ", unpack("H*", $ISKb_unorder), "\n\n";

FUNCTION

calculate_generator

my ($G, $params_ref) = calculate_generator( $DSI, $PRS, $CI, $sid, $group_name, $type, $hash_name, $expand_message_xmd_func, $clear_cofactor_flag );

prepare_send_msg

my ($msg, $point, $rnd) = prepare_send_msg( $group, $G, $rnd, $point_hex_type, $ctx, $AD);

parse_recv_msg

my @data = parse_recv_msg($msg_recv);

prepare_ISK

my $ISK = prepare_ISK( $DSI, $sid, $group, $rnd, $msg_send, $msg_recv, $is_initiator, $is_unorder, $hash_name, $ctx );

crypt-cpace's People

Contributors

abbypan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.