anchor.diff:  %%--------------------------------------------------------------------
   %% %CopyrightBegin%
   %%
  -%% Copyright Ericsson AB 2012. All Rights Reserved.
  +%% Copyright Ericsson AB 2013. All Rights Reserved.
   %%
   %% The contents of this file are subject to the Erlang Public License,
   %% Version 1.1, (the "License"); you may not use this file except in
  
positive.code: encode_key(Key = #'DSAPrivateKey'{}) ->
      Der = public_key:der_encode('DSAPrivateKey', Key),
      {'DSAPrivateKey', Der, not_encrypted}.
  
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% DSA key generation  (OBS: for testing only)
  
negative.code:     Q  = prime(NSize),  %% Choose N-bit prime Q
      X0 = prime(LSize),
      P0 = prime((LSize div 2) +1),
      
      %% Choose L-bit prime modulus P such that p-1 is a multiple of q.
      case dsa_search(X0 div (2*Q*P0), P0, Q, 1000) of
  	error -> 
  	    gen_dsa2(LSize, NSize);
  	P ->	    
  	    G = crypto:mod_pow(2, (P-1) div Q, P), % Choose G a number whose multiplicative order modulo p is q.
  	    %%                 such that This may be done by setting g = h^(p-1)/q mod p, commonly h=2 is used.
  	    
  	    X = prime(20),               %% Choose x by some random method, where 0 < x < q.
  	    Y = crypto:mod_pow(G, X, P), %% Calculate y = g^x mod p.
  	    
  	    #'DSAPrivateKey'{version=0, p = P, q = Q, 
  			     g = crypto:binary_to_integer(G), y = crypto:binary_to_integer(Y), x = X}
      end.
      
  %% See fips_186-3.pdf
  dsa_search(T, P0, Q, Iter) when Iter > 0 ->
      P = 2*T*Q*P0 + 1,
      case is_prime(P, 50) of
  	true -> P;
  	false -> dsa_search(T+1, P0, Q, Iter-1)
      end;
  dsa_search(_,_,_,_) -> 
      error.
  
  
  %%%%%%% Crypto Math %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  prime(ByteSize) ->
      Rand = odd_rand(ByteSize),
      prime_odd(Rand, 0).
  
  prime_odd(Rand, N) ->
      case is_prime(Rand, 50) of
  	true -> 
  	    Rand;
  	false -> 
  	    prime_odd(Rand+2, N+1)
      end.
  
  %% see http://en.wikipedia.org/wiki/Fermat_primality_test
  is_prime(_, 0) -> true;
  is_prime(Candidate, Test) -> 
      CoPrime = odd_rand(10000, Candidate),
      Result = crypto:mod_pow(CoPrime, Candidate, Candidate) ,
      is_prime(CoPrime, crypto:binary_to_integer(Result), Candidate, Test).
  
  is_prime(CoPrime, CoPrime, Candidate, Test) ->
      is_prime(Candidate, Test-1);
  is_prime(_,_,_,_) ->
      false.
  
  odd_rand(Size) ->
      Min = 1 bsl (Size*8-1),
      Max = (1 bsl (Size*8))-1,
      odd_rand(Min, Max).
  
  odd_rand(Min,Max) ->
      Rand = crypto:rand_uniform(Min,Max),
      case Rand rem 2 of
  	0 -> 
  	    Rand + 1;
  	_ -> 
  	    Rand
      end.
  
  copyfile(SrcDir, DstDir, Fn) ->
  