ADDED tools.gpr Index: tools.gpr ================================================================== --- tools.gpr +++ tools.gpr @@ -0,0 +1,17 @@ +with "natools"; + +project Tools is + for Source_Dirs use ("tools"); + for Main use ("hmac-md5", "hmac-sha1", "hmac-sha256"); + + for Object_Dir use Natools'Object_Dir; + for Exec_Dir use Natools'Exec_Dir; + + package Compiler is + for Default_Switches use Natools.Compiler'Default_Switches; + end Compiler; + + package Linker is + for Default_Switches use Natools.Linker'Default_Switches; + end Linker; +end Tools; ADDED tools/hmac-main.adb Index: tools/hmac-main.adb ================================================================== --- tools/hmac-main.adb +++ tools/hmac-main.adb @@ -0,0 +1,68 @@ +------------------------------------------------------------------------------ +-- Copyright (c) 2014, Natacha Porté -- +-- -- +-- Permission to use, copy, modify, and distribute this software for any -- +-- purpose with or without fee is hereby granted, provided that the above -- +-- copyright notice and this permission notice appear in all copies. -- +-- -- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- +-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- +-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- +-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- +-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- +-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- +-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- +------------------------------------------------------------------------------ + +with Ada.Command_Line; +with Ada.Streams; +with Ada.Text_IO; +with Ada.Text_IO.Text_Streams; + +with Natools.S_Expressions; +with Natools.S_Expressions.Encodings; + +procedure HMAC.Main is +begin + case Ada.Command_Line.Argument_Count is + when 0 => + Ada.Text_IO.Put_Line ("Usage: " + & Ada.Command_Line.Command_Name + & " key [message]"); + + when 1 => + declare + Context : HMAC_Implementation.Context + := HMAC_Implementation.Create (Ada.Command_Line.Argument (1)); + Block : Ada.Streams.Stream_Element_Array (1 .. 64); + Last : Ada.Streams.Stream_Element_Offset; + Input : constant Ada.Text_IO.Text_Streams.Stream_Access + := Ada.Text_IO.Text_Streams.Stream (Ada.Text_IO.Current_Input); + begin + loop + Input.Read (Block, Last); + exit when Last not in Block'Range; + HMAC_Implementation.Update + (Context, Block (Block'First .. Last)); + end loop; + + Ada.Text_IO.Put_Line + (Natools.S_Expressions.To_String + (Natools.S_Expressions.Encodings.Encode_Hex + (HMAC_Implementation.Digest (Context), + Natools.S_Expressions.Encodings.Lower))); + end; + + when others => + for I in 2 .. Ada.Command_Line.Argument_Count loop + Ada.Text_IO.Put_Line + (Natools.S_Expressions.To_String + (Natools.S_Expressions.Encodings.Encode_Hex + (HMAC_Implementation.Digest + (Ada.Command_Line.Argument (1), + Natools.S_Expressions.To_Atom + (Ada.Command_Line.Argument (I))), + Natools.S_Expressions.Encodings.Lower))); + end loop; + end case; +end HMAC.Main; ADDED tools/hmac-main.ads Index: tools/hmac-main.ads ================================================================== --- tools/hmac-main.ads +++ tools/hmac-main.ads @@ -0,0 +1,27 @@ +------------------------------------------------------------------------------ +-- Copyright (c) 2014, Natacha Porté -- +-- -- +-- Permission to use, copy, modify, and distribute this software for any -- +-- purpose with or without fee is hereby granted, provided that the above -- +-- copyright notice and this permission notice appear in all copies. -- +-- -- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- +-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- +-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- +-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- +-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- +-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- +-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- +------------------------------------------------------------------------------ + +------------------------------------------------------------------------------ +-- HMAC.Main provides a generic main procedure tailored for the given HMAC -- +-- implementation. -- +------------------------------------------------------------------------------ + +with Natools.HMAC; + +generic + with package HMAC_Implementation is new Natools.HMAC (<>); + +procedure HMAC.Main; ADDED tools/hmac-md5.ads Index: tools/hmac-md5.ads ================================================================== --- tools/hmac-md5.ads +++ tools/hmac-md5.ads @@ -0,0 +1,20 @@ +------------------------------------------------------------------------------ +-- Copyright (c) 2014, Natacha Porté -- +-- -- +-- Permission to use, copy, modify, and distribute this software for any -- +-- purpose with or without fee is hereby granted, provided that the above -- +-- copyright notice and this permission notice appear in all copies. -- +-- -- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- +-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- +-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- +-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- +-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- +-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- +-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- +------------------------------------------------------------------------------ + +with HMAC.Main; +with Natools.GNAT_HMAC.MD5; + +procedure HMAC.MD5 is new HMAC.Main (Natools.GNAT_HMAC.MD5); ADDED tools/hmac-sha1.ads Index: tools/hmac-sha1.ads ================================================================== --- tools/hmac-sha1.ads +++ tools/hmac-sha1.ads @@ -0,0 +1,20 @@ +------------------------------------------------------------------------------ +-- Copyright (c) 2014, Natacha Porté -- +-- -- +-- Permission to use, copy, modify, and distribute this software for any -- +-- purpose with or without fee is hereby granted, provided that the above -- +-- copyright notice and this permission notice appear in all copies. -- +-- -- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- +-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- +-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- +-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- +-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- +-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- +-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- +------------------------------------------------------------------------------ + +with HMAC.Main; +with Natools.GNAT_HMAC.SHA1; + +procedure HMAC.SHA1 is new HMAC.Main (Natools.GNAT_HMAC.SHA1); ADDED tools/hmac-sha256.ads Index: tools/hmac-sha256.ads ================================================================== --- tools/hmac-sha256.ads +++ tools/hmac-sha256.ads @@ -0,0 +1,20 @@ +------------------------------------------------------------------------------ +-- Copyright (c) 2014, Natacha Porté -- +-- -- +-- Permission to use, copy, modify, and distribute this software for any -- +-- purpose with or without fee is hereby granted, provided that the above -- +-- copyright notice and this permission notice appear in all copies. -- +-- -- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- +-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- +-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- +-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- +-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- +-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- +-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- +------------------------------------------------------------------------------ + +with HMAC.Main; +with Natools.GNAT_HMAC.SHA256; + +procedure HMAC.SHA256 is new HMAC.Main (Natools.GNAT_HMAC.SHA256); ADDED tools/hmac.ads Index: tools/hmac.ads ================================================================== --- tools/hmac.ads +++ tools/hmac.ads @@ -0,0 +1,26 @@ +------------------------------------------------------------------------------ +-- Copyright (c) 2014, Natacha Porté -- +-- -- +-- Permission to use, copy, modify, and distribute this software for any -- +-- purpose with or without fee is hereby granted, provided that the above -- +-- copyright notice and this permission notice appear in all copies. -- +-- -- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- +-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- +-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- +-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- +-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- +-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- +-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- +------------------------------------------------------------------------------ + +------------------------------------------------------------------------------ +-- HMAC is an empty parent package for main procedures of HMAC computing -- +-- tools. -- +------------------------------------------------------------------------------ + + +package HMAC is + pragma Pure (HMAC); + +end HMAC;