Rem BasicCard Sample Source Code
Rem ------------------------------------------------------------------
Rem Copyright (C) 1997-2008 ZeitControl GmbH
Rem You have a royalty-free right to use, modify, reproduce and 
Rem distribute the Sample Application Files (and/or any modified 
Rem version) in any way you find useful, provided that you agree 
Rem that ZeitControl GmbH has no warranty, obligations or liability
Rem for any Sample Application Files.
Rem ------------------------------------------------------------------

#Include ECCARD.DEF

Sub CheckLibError()
  Private S$
  Select Case LibError
    Case 0: Exit Sub
    Case Else: S$ = "&H" + Right$ ("000" + Hex$(LibError), 4)
  End Select

  Print "Error in library procedure: LibError = " + S$
  Exit

End Sub

Function BuildKeyForCurve(Curve%, KeyData$) as String
  ' Build a predicatble key for use in test programs
  Private keylen=0
  Private temp$
  select case Curve%
     case 1, 2 : keylen=160 : exit case 
     case 3, 4 : keylen=192 : exit case 
     case 5, 6 : keylen=224 : exit case 
     case 7, 8 : keylen=256 : exit case 
     case 9, 10 : keylen=320 : exit case 
     case 11, 12 : keylen=384 : exit case 
     case 13, 14 : keylen=512 : exit case 
  end select
  keylen=keylen/8
  if Len(KeyData$)=0 then KeyData$=Chr$(0)
  temp$=""
  while Len(temp$)<keylen
     temp$=temp$+KeyData$
  wend
  temp$(1)=Chr$(Asc(temp$(1)) AND &H7F)
  BuildKeyForCurve=Left$(temp$, keylen)
End Function
