\doxysection{bgpsec\+\_\+utils\+\_\+private.\+h}
\hypertarget{bgpsec__utils__private_8h_source}{}\label{bgpsec__utils__private_8h_source}\index{rtrlib/bgpsec/bgpsec\_utils\_private.h@{rtrlib/bgpsec/bgpsec\_utils\_private.h}}
\mbox{\hyperlink{bgpsec__utils__private_8h}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*}}
\DoxyCodeLine{00002\ \textcolor{comment}{\ *\ This\ file\ is\ part\ of\ RTRlib.}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ This\ file\ is\ subject\ to\ the\ terms\ and\ conditions\ of\ the\ MIT\ license.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *\ See\ the\ file\ LICENSE\ in\ the\ top\ level\ directory\ for\ more\ details.}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ Website:\ http://rtrlib.realmv6.org/}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00009\ }
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#ifndef\ RTR\_BGPSEC\_UTILS\_PRIVATE\_H}}
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#define\ RTR\_BGPSEC\_UTILS\_PRIVATE\_H}}
\DoxyCodeLine{00012\ }
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{bgpsec_8h}{rtrlib/bgpsec/bgpsec.h}}"{}}}
\DoxyCodeLine{00014\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{alloc__utils__private_8h}{rtrlib/lib/alloc\_utils\_private.h}}"{}}}
\DoxyCodeLine{00015\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{log__private_8h}{rtrlib/lib/log\_private.h}}"{}}}
\DoxyCodeLine{00016\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{rtrlib__export__private_8h}{rtrlib/rtrlib\_export\_private.h}}"{}}}
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00018\ \textcolor{preprocessor}{\#include\ <arpa/inet.h>}}
\DoxyCodeLine{00019\ \textcolor{preprocessor}{\#include\ <openssl/x509.h>}}
\DoxyCodeLine{00020\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00022\ \textcolor{preprocessor}{\#define\ BGPSEC\_DBG(fmt,\ ...)\ lrtr\_dbg("{}BGPSEC:\ "{}\ fmt,\ \#\#\_\_VA\_ARGS\_\_)}}
\DoxyCodeLine{00023\ \textcolor{preprocessor}{\#define\ BGPSEC\_DBG1(a)\ lrtr\_dbg("{}BGPSEC:\ "{}\ a)}}
\DoxyCodeLine{00024\ }
\DoxyCodeLine{00028\ \textcolor{preprocessor}{\#define\ SECURE\_PATH\_SEG\_SIZE\ 6}}
\DoxyCodeLine{00029\ }
\DoxyCodeLine{00031\ \textcolor{preprocessor}{\#define\ SKI\_STR\_LEN\ 61}}
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00034\ \textcolor{preprocessor}{\#define\ PRIVATE\_KEY\_LENGTH\ 121L}}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00038\ \textcolor{keyword}{enum}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ac93d27f6095940798150fd9cc61e8db3}{align\_type}}\ \{}
\DoxyCodeLine{00039\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{bgpsec__utils__private_8h_ac93d27f6095940798150fd9cc61e8db3a7721bbfbdf88038c07a667176e9ab22c}{VALIDATION}},}
\DoxyCodeLine{00040\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{bgpsec__utils__private_8h_ac93d27f6095940798150fd9cc61e8db3a34bc8689edea431068fb64025f6e5d0c}{SIGNING}},}
\DoxyCodeLine{00041\ \};}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ \textcolor{comment}{/*\ Forward\ declaration\ of\ stream\ to\ make\ it\ opaque.\ */}}
\DoxyCodeLine{00044\ \textcolor{keyword}{struct\ }stream;}
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00046\ \textcolor{comment}{/*\ Initialize\ and\ return\ a\ stream\ of\ size\ bytes\ or\ NULL\ if\ the\ memory\ allocation\ failed\ */}}
\DoxyCodeLine{00047\ \textcolor{keyword}{struct\ }stream\ *\mbox{\hyperlink{bgpsec__utils__private_8h_a6b685c5cfe8237f8aac2c723f86ae24a}{init\_stream}}(uint16\_t\ size);}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00049\ \textcolor{comment}{/*\ Copy\ a\ stream\ s\ and\ return\ the\ copy\ or\ NULL\ if\ the\ memory\ allocation\ failed\ */}}
\DoxyCodeLine{00050\ \textcolor{keyword}{struct\ }stream\ *\mbox{\hyperlink{bgpsec__utils__private_8h_a99edb0f324129b558fc1dcc6194aeaf7}{copy\_stream}}(\textcolor{keyword}{struct}\ stream\ *s);}
\DoxyCodeLine{00051\ }
\DoxyCodeLine{00052\ \textcolor{comment}{/*\ Free\ stream\ s\ */}}
\DoxyCodeLine{00053\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{bgpsec__utils__private_8h_a92276a87f1d7b8002362e528bbaafee6}{free\_stream}}(\textcolor{keyword}{struct}\ stream\ *s);}
\DoxyCodeLine{00054\ }
\DoxyCodeLine{00055\ \textcolor{comment}{/*\ Write\ len\ bytes\ from\ data\ to\ stream\ s\ */}}
\DoxyCodeLine{00056\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{bgpsec__utils__private_8h_aff96997757c81776d4d9330fe5a92c0d}{write\_stream}}(\textcolor{keyword}{struct}\ stream\ *s,\ \textcolor{keywordtype}{void}\ *data,\ uint16\_t\ \mbox{\hyperlink{rtr__pdus_8h_a96bbf959016e4411c9e6b9812a8be60a}{len}});}
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ \textcolor{comment}{/*\ Get\ the\ start\ position\ pointer\ of\ stream\ s\ */}}
\DoxyCodeLine{00059\ uint8\_t\ *\mbox{\hyperlink{bgpsec__utils__private_8h_a844b6b7c0cc5f45d7d51beb079ab182c}{get\_stream\_start}}(\textcolor{keyword}{struct}\ stream\ *s);}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ \textcolor{comment}{/*\ Get\ the\ size\ of\ the\ storable\ data\ of\ stream\ s\ */}}
\DoxyCodeLine{00062\ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ae6a90b39cfa02546e1581c1f0a4acf2d}{get\_stream\_size}}(\textcolor{keyword}{struct}\ stream\ *s);}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00064\ \textcolor{comment}{/*\ Read\ one\ byte\ from\ stream\ s\ */}}
\DoxyCodeLine{00065\ uint8\_t\ \mbox{\hyperlink{bgpsec__utils__private_8h_aa759f1b9cda97b8b677406420453a3a6}{read\_stream}}(\textcolor{keyword}{struct}\ stream\ *s);}
\DoxyCodeLine{00066\ }
\DoxyCodeLine{00067\ \textcolor{comment}{/*\ Read\ len\ bytes\ from\ stream\ s\ and\ write\ them\ to\ buff\ */}}
\DoxyCodeLine{00068\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ae80e62a25bca98bed7107b53377226db}{read\_n\_bytes\_stream}}(uint8\_t\ *buff,\ \textcolor{keyword}{struct}\ stream\ *s,\ uint16\_t\ \mbox{\hyperlink{rtr__pdus_8h_a96bbf959016e4411c9e6b9812a8be60a}{len}});}
\DoxyCodeLine{00069\ }
\DoxyCodeLine{00070\ \textcolor{comment}{/*\ Read\ len\ bytes\ from\ stream\ s,\ starting\ from\ position\ start\ and\ write}}
\DoxyCodeLine{00071\ \textcolor{comment}{\ *\ the\ result\ to\ buff.}}
\DoxyCodeLine{00072\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00073\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{bgpsec__utils__private_8h_a238bc2b424cb156213f21a337afedca0}{read\_stream\_at}}(uint8\_t\ *buff,\ \textcolor{keyword}{struct}\ stream\ *s,\ uint16\_t\ start,\ uint16\_t\ \mbox{\hyperlink{rtr__pdus_8h_a96bbf959016e4411c9e6b9812a8be60a}{len}});}
\DoxyCodeLine{00074\ }
\DoxyCodeLine{00075\ \textcolor{comment}{/*\ Calculate\ the\ reqired\ size\ for\ a\ stream,\ so\ that\ all\ information\ from\ data}}
\DoxyCodeLine{00076\ \textcolor{comment}{\ *\ fit\ into\ it.\ type\ controls,\ if\ it\ is\ for\ validation\ or\ signing\ purposes.}}
\DoxyCodeLine{00077\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00078\ \textcolor{keywordtype}{size\_t}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ab5e5c3e57d6379bf573648fea34c05c5}{req\_stream\_size}}(\textcolor{keyword}{const}\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structrtr__bgpsec}{rtr\_bgpsec}}\ *data,\ \textcolor{keyword}{enum}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ac93d27f6095940798150fd9cc61e8db3}{align\_type}}\ \mbox{\hyperlink{rtr__pdus_8h_a1d127017fb298b889f4ba24752d08b8e}{type}});}
\DoxyCodeLine{00079\ }
\DoxyCodeLine{00080\ \textcolor{comment}{/*\ Get\ the\ length\ in\ bytes\ for\ a\ all\ signature\ segments\ */}}
\DoxyCodeLine{00081\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_afdae4ebd000267e60e29baf47574bd8f}{get\_sig\_seg\_size}}(\textcolor{keyword}{const}\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structrtr__signature__seg}{rtr\_signature\_seg}}\ *sig\_segs,\ \textcolor{keyword}{enum}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ac93d27f6095940798150fd9cc61e8db3}{align\_type}}\ \mbox{\hyperlink{rtr__pdus_8h_a1d127017fb298b889f4ba24752d08b8e}{type}});}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00083\ \textcolor{comment}{/*\ Check,\ if\ there\ is\ at\ least\ one\ router\ key\ for\ each\ SKI\ from\ sig\_segs.\ */}}
\DoxyCodeLine{00084\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_a5d2757737865dbaa06ee1a46aa2a3260}{check\_router\_keys}}(\textcolor{keyword}{const}\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structrtr__signature__seg}{rtr\_signature\_seg}}\ *sig\_segs,\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structspki__table}{spki\_table}}\ *table);}
\DoxyCodeLine{00085\ }
\DoxyCodeLine{00086\ \textcolor{comment}{/*\ Store\ the\ string\ representation\ of\ a\ BGPsec\_PATH\ segment\ in\ buffer.\ */}}
\DoxyCodeLine{00087\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_afb3f2a91ccd096d6ef08177579daa792}{bgpsec\_segment\_to\_str}}(\textcolor{keywordtype}{char}\ *buffer,\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structrtr__signature__seg}{rtr\_signature\_seg}}\ *sig\_seg,\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structrtr__secure__path__seg}{rtr\_secure\_path\_seg}}\ *sec\_path);}
\DoxyCodeLine{00088\ }
\DoxyCodeLine{00089\ \textcolor{comment}{/*\ Store\ the\ hex-\/string\ representation\ of\ a\ byte\ sequence\ in\ buffer.\ */}}
\DoxyCodeLine{00090\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ac6317dc0c414dccee0d1aa9061080cbf}{byte\_sequence\_to\_str}}(\textcolor{keywordtype}{char}\ *buffer,\ uint8\_t\ *bytes,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ bytes\_len,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ tabstops);}
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00092\ \textcolor{comment}{/*\ Takes\ a\ binary\ encoded\ SKI\ and\ stores\ it\ in\ ski\_str\ as\ a\ human\ readable}}
\DoxyCodeLine{00093\ \textcolor{comment}{\ *\ hex\ string.}}
\DoxyCodeLine{00094\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00095\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ab55c3562ce712c145c2ca1173e67f8df}{ski\_to\_char}}(\textcolor{keywordtype}{char}\ *ski\_str,\ uint8\_t\ *\mbox{\hyperlink{rtr__pdus_8h_a12038882b8c1e8109c0e4b1ea6f8cb5c}{ski}});}
\DoxyCodeLine{00096\ }
\DoxyCodeLine{00097\ \textcolor{comment}{/*\ Align\ the\ BGPsec\ data\ as\ a\ byte\ sequence\ and\ store\ it\ in\ stream\ s.\ type}}
\DoxyCodeLine{00098\ \textcolor{comment}{\ *\ controls,\ if\ the\ alignment\ is\ for\ validation\ or\ signing.}}
\DoxyCodeLine{00099\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00100\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_a2f4b251ebabba57068f95e5fd3743ca7}{align\_byte\_sequence}}(\textcolor{keyword}{const}\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structrtr__bgpsec}{rtr\_bgpsec}}\ *data,\ \textcolor{keyword}{struct}\ stream\ *s,\ \textcolor{keyword}{enum}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ac93d27f6095940798150fd9cc61e8db3}{align\_type}}\ \mbox{\hyperlink{rtr__pdus_8h_a1d127017fb298b889f4ba24752d08b8e}{type}});}
\DoxyCodeLine{00101\ }
\DoxyCodeLine{00102\ \textcolor{comment}{/*\ Hash\ a\ byte\ sequence\ and\ store\ it\ in\ result\_buffer.\ */}}
\DoxyCodeLine{00103\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_aa0aaca9cac4a1f48846d9ce2a59eeda0}{hash\_byte\_sequence}}(uint8\_t\ *bytes,\ \textcolor{keywordtype}{size\_t}\ bytes\_len,\ uint8\_t\ alg\_suite\_id,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{char}\ **result\_buffer);}
\DoxyCodeLine{00104\ }
\DoxyCodeLine{00105\ \textcolor{comment}{/*\ Validate\ a\ signature\ sig.\ */}}
\DoxyCodeLine{00106\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_a88e92a2a39b3f497a17f3c555c9fc801}{validate\_signature}}(\textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{char}\ *hash,\ \textcolor{keyword}{const}\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structrtr__signature__seg}{rtr\_signature\_seg}}\ *sig,\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structspki__record}{spki\_record}}\ *record);}
\DoxyCodeLine{00107\ }
\DoxyCodeLine{00108\ \textcolor{comment}{/*\ Load\ a\ binary\ private\ key\ bytes\_key\ and\ store\ it\ in\ the\ openssl\ EC\_KEY}}
\DoxyCodeLine{00109\ \textcolor{comment}{\ *\ priv\_key.}}
\DoxyCodeLine{00110\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00111\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ada1184ccfb82bafb76006a79a6409142}{load\_private\_key}}(EC\_KEY\ **priv\_key,\ uint8\_t\ *bytes\_key);}
\DoxyCodeLine{00112\ }
\DoxyCodeLine{00113\ \textcolor{comment}{/*\ Load\ a\ binary\ public\ key\ spki\ and\ store\ it\ in\ the\ openssl\ EC\_KEY}}
\DoxyCodeLine{00114\ \textcolor{comment}{\ *\ pub\_key.}}
\DoxyCodeLine{00115\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00116\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_ab26250c7b541e8e5b8b2253688d8396e}{load\_public\_key}}(EC\_KEY\ **pub\_key,\ uint8\_t\ *\mbox{\hyperlink{rtr__pdus_8h_a4b4ec32d54b57f9de44ec9bb55838d5c}{spki}});}
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00118\ \textcolor{comment}{/*\ Sign\ a\ byte\ sequence,\ depending\ on\ the\ algorithm\ suite.\ The\ signature\ and}}
\DoxyCodeLine{00119\ \textcolor{comment}{\ *\ its\ length\ are\ stored\ in\ new\_signature.}}
\DoxyCodeLine{00120\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00121\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_a749a96362572194bd3933522f2c7e05d}{sign\_byte\_sequence}}(uint8\_t\ *hash\_result,\ EC\_KEY\ *priv\_key,\ uint8\_t\ alg,\ \textcolor{keyword}{struct}\ \mbox{\hyperlink{structrtr__signature__seg}{rtr\_signature\_seg}}\ *new\_signature);}
\DoxyCodeLine{00122\ }
\DoxyCodeLine{00123\ \textcolor{comment}{/*\ Check,\ if\ all\ elements\ of\ a\ SKI\ are\ 0.\ */}}
\DoxyCodeLine{00124\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{bgpsec__utils__private_8h_a70f44e6e07e994617df730c819d44349}{ski\_is\_empty}}(uint8\_t\ *\mbox{\hyperlink{rtr__pdus_8h_a12038882b8c1e8109c0e4b1ea6f8cb5c}{ski}});}
\DoxyCodeLine{00125\ }
\DoxyCodeLine{00126\ \textcolor{preprocessor}{\#endif}}

\end{DoxyCode}
